Ejemplo n.º 1
0
        /// <summary>
        /// Transforms the data grid view values into a list of language strings and returns that list of language strings
        /// </summary>
        private List <LanguageStrings> TransformDgvValuesToLanguageStrings()
        {
            var retVal = new List <LanguageStrings>();

            foreach (DataGridViewColumn column in dgvRotatedLanguages.Columns)
            {
                if (column.Index > 0)
                {
                    var languageFile = new LanguageStrings();
                    for (int rowIndex = 0; rowIndex < dgvRotatedLanguages.RowCount; rowIndex++)
                    {
                        var property = languageFile.GetType().GetProperties().Where(x => x.Name == dgvRotatedLanguages.Rows[rowIndex].Cells[0].Value?.ToString()).FirstOrDefault();
                        if (property.Name == "Culture")
                        {
                            property.SetValue(languageFile, new CultureInfo(dgvRotatedLanguages.Rows[rowIndex].Cells[column.Index].Value?.ToString()));
                        }
                        else
                        {
                            property.SetValue(languageFile, dgvRotatedLanguages.Rows[rowIndex].Cells[column.Index].Value?.ToString());
                        }
                    }
                    retVal.Add(languageFile);
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
 public static void LoadLanguageFile(CultureInfo culture, string additionalCultureInfo, string languageFolderPath)
 {
     try
     {
         var languageFiles = Directory.GetFiles(languageFolderPath);
         foreach (var languageFile in languageFiles)
         {
             var fileInfo = new FileInfo(languageFile);
             if (fileInfo.Name.ToLower().Contains("_" + culture.Name.ToLower()))
             {
                 if (string.IsNullOrWhiteSpace(additionalCultureInfo) == false && fileInfo.Name.ToLower().Contains("_" + additionalCultureInfo.ToLower()))
                 {
                     var languageJson = File.ReadAllText(fileInfo.FullName);
                     Translation.LanguageStrings = JsonConvert.DeserializeObject <LanguageStrings>(languageJson);
                     break;
                 }
                 else if (string.IsNullOrWhiteSpace(additionalCultureInfo) == true)
                 {
                     var languageJson = File.ReadAllText(fileInfo.FullName);
                     Translation.LanguageStrings = JsonConvert.DeserializeObject <LanguageStrings>(languageJson);
                     break;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }