Esempio n. 1
0
 private void LoadGrid(string filePath = "")
 {
     try
     {
         if (string.IsNullOrEmpty(filePath))
         {
             filePath = Others.DialogBoxOpenFile(Application.StartupPath + @"\Data\Lang\", "Langage files (*.xml)|*.xml");
         }
         if (File.Exists(filePath))
         {
             Translate.Language currentLangage = XmlSerializer.Deserialize <Translate.Language>(filePath);
             CheckIdListAndReOrganize(ref currentLangage);
             for (int i = 0; i <= _defaultLangage.Translations.Count - 1; i++)
             {
                 if (string.IsNullOrEmpty(currentLangage.Translations[i].Text) || currentLangage.Translations[i].Text == currentLangage.Translations[i].Id.ToString() ||
                     currentLangage.Translations[i].Text.Contains("_"))
                 {
                     currentLangage.Translations[i].Text = _defaultLangage.Translations[i].Text;
                 }
             }
             TranslationTable.Rows.Clear();
             for (int i = 0; i < _defaultLangage.Translations.Count; i++)
             {
                 Translate.Translation translation = _defaultLangage.Translations[i];
                 TranslationTable.Rows.Add(new object[] { translation.Id.ToString(), currentLangage.Translations[i].Text, translation.Text });
             }
         }
     }
     catch (Exception ex)
     {
         Logging.WriteError("Translate_Tools > LoadGrid(string filePath): " + ex);
     }
 }
        private string GetLanguageCodeFor(Translate.Language language)
        {
            if (!_supportedLanguages.ContainsKey(language))
            {
                throw new ArgumentException($"{language} is not supported.");
            }

            return(_supportedLanguages[language]);
        }
Esempio n. 3
0
 private void CheckIdListAndReOrganize(ref Translate.Language lang)
 {
     for (int i = 0; i <= _defaultLangage.Translations.Count - 1; i++)
     {
         if (lang.Translations.Count - 1 > i)
         {
             if (_defaultLangage.Translations[i].Id != lang.Translations[i].Id)
             {
                 bool   found     = false;
                 int    foundAt   = 0;
                 string textFound = "";
                 for (int j = 0; j < lang.Translations.Count - 1; j++)
                 {
                     if (lang.Translations[j].Id == _defaultLangage.Translations[i].Id)
                     {
                         found     = true;
                         foundAt   = j;
                         textFound = lang.Translations[j].Text;
                         break;
                     }
                 }
                 if (found)
                 {
                     lang.Translations.RemoveAt(foundAt);
                     if (string.IsNullOrEmpty(textFound))
                     {
                         textFound = _defaultLangage.Translations[i].Text;
                     }
                     lang.Translations.Insert(i, new Translate.Translation {
                         Id = _defaultLangage.Translations[i].Id, Text = textFound
                     });
                 }
                 else
                 {
                     lang.Translations.Insert(i, _defaultLangage.Translations[i]);
                 }
             }
         }
         else if (lang.Translations.Count - 1 < i && i != _defaultLangage.Translations.Count)
         {
             lang.Translations.Insert(i, _defaultLangage.Translations[i]);
         }
     }
     while (_defaultLangage.Translations.Count < lang.Translations.Count)
     {
         lang.Translations.RemoveAt(lang.Translations.Count - 1);
     }
 }