コード例 #1
0
        private static void ImportPoFile(object sender, DoWorkEventArgs e)
        {
            List <object> paramsList = e.Argument as List <object>;

            Localization localization = paramsList[0] as Localization;
            string       fileName     = paramsList[1] as string;

            string[] strings        = File.ReadAllLines(fileName);
            PoFile   poFile         = new PoFile(strings);
            string   poFileLanguage = poFile.PoFileLanguage;

            localization.AddPoFile(poFile);

            if (!localization.IsNewPoFileLangugage(poFileLanguage))
            {
                int fieldsCount = poFile.LocalizationFields.Count;

                for (int i = 0; i < fieldsCount; i++)
                {
                    if (ImportHandler != null && ImportHandler.CancellationPending == true)
                    {
                        break;
                    }
                    else
                    {
                        localization.AddFields(poFile.LocalizationFields[i]);
                        if (ImportHandler != null)
                        {
                            ImportHandler.ReportProgress(Convert.ToInt32(((double)i / fieldsCount) * 100), i);
                        }
                    }
                }
            }
        }
コード例 #2
0
 public void AddPoFile(PoFile poFile)
 {
     if (CurrentPoFileLanguage == "")
     {
         CurrentPoFileLanguage = poFile.PoFileLanguage;
     }
     PoFilesMap[poFile.PoFileLanguage] = poFile;
 }
コード例 #3
0
        public void SetLocalizationByPoFile(string poFileLanguage)
        {
            LocalizationFields.Clear();
            CurrentPoFileLanguage = poFileLanguage;
            PoFile poFile = PoFilesMap[poFileLanguage];

            foreach (LocalizationField field in poFile.LocalizationFields)
            {
                AddFields(field);
            }

            OnLocalizationUpdated();
        }
コード例 #4
0
        public static void ImportJson(Localization localization, string fileName)
        {
            string jsonString = File.ReadAllText(fileName);

            Localization outLocalization = new Localization();

            outLocalization = JsonConvert.DeserializeObject <Localization>(jsonString);

            localization.AddFields(outLocalization.LocalizationFields);

            PoFile poFile = localization.GetCurrentPoFile();

            string field = poFile.LocalizationFields[1].TranslationString;

            OnFileImported();
        }
コード例 #5
0
        public static void ExportToPoFile(Localization localization, string fileName)
        {
            PoFile targetPoFile = null;

            if (File.Exists(fileName))
            {
                string[] strings = File.ReadAllLines(fileName);
                targetPoFile = new PoFile(strings);
            }

            else
            {
                if (localization.PoFilesMap.Count > 0)
                {
                    targetPoFile = localization.GetCurrentPoFile();
                }
            }

            if (targetPoFile != null)
            {
                targetPoFile.ReplaceTranslationByLocalization(localization);
                File.WriteAllLines(fileName, targetPoFile.File);
            }
        }