private void GenerateTestFiles() { BLanguageSet objAuxTest; try { if (!Directory.Exists(Path.Combine(".", "locales"))) { Directory.CreateDirectory(Path.Combine(".", "locales")); } if (File.Exists(Path.Combine(".", "locales", "pt-br.json"))) { File.Delete(Path.Combine(".", "locales", "pt-br.json")); } if (File.Exists(Path.Combine(".", "locales", "en-us.json"))) { File.Delete(Path.Combine(".", "locales", "en-us.json")); } if (!File.Exists(Path.Combine(".", "locales", "pt-br.json"))) { objAuxTest = new BLanguageSet(new List <BLanguageItem>() { new BLanguageItem("group_one.text_one", "text 1 pt"), new BLanguageItem("group_one.text_two", "text 2 pt"), new BLanguageItem("group_one.text_three", "text 3 pt"), new BLanguageItem("group_one.text_four", "text 4 pt"), new BLanguageItem("group_two.text_five", "text 5 pt"), new BLanguageItem("group_two.text_six", "text 6 pt"), new BLanguageItem("group_two.text_seven", "text 7 pt"), new BLanguageItem("group_two.text_eight", "text 8 pt"), new BLanguageItem("group_two.sub_group.text_nine", "text 9 pt"), }, "pt-br"); LanguageFileConverter.SaveLanguageFile(objAuxTest, Path.Combine(".", "locales")); } if (!File.Exists(Path.Combine(".", "locales", "en-us.json"))) { objAuxTest = new BLanguageSet(new List <BLanguageItem>() { new BLanguageItem("group_one.text_one", "text 1 us"), new BLanguageItem("group_one.text_two", "text 2 us"), new BLanguageItem("group_one.text_three", "text 3 us"), new BLanguageItem("group_one.text_four", "text 4 us"), new BLanguageItem("group_two.text_five", "text 5 us"), new BLanguageItem("group_two.text_six", "text 6 us"), new BLanguageItem("group_two.text_seven", "text 7 us"), new BLanguageItem("group_two.text_eight", "text 8 us"), new BLanguageItem("group_two.sub_group.text_nine", "text 9 us"), }, "en-us"); LanguageFileConverter.SaveLanguageFile(objAuxTest, Path.Combine(".", "locales")); } } catch (Exception) { throw; } }
private void LoadFolder(string p_strPath) { string[] strFiles; try { strBasePath = p_strPath; if (string.IsNullOrEmpty(strBasePath)) { strBasePath = "."; } strFiles = Directory.GetFiles(strBasePath, "*.json"); objLanguageSets = new List <BLanguageSet>(); strLanguageSetsKeys = new List <string>(); foreach (string file in strFiles) { try { objLanguageSets.Add(LanguageFileConverter.LoadLanguageFile(file)); strLanguageSetsKeys.Add(objLanguageSets.Last().LanguageKey); } catch (Exception) { } } } catch (Exception) { throw; } }
public List <string> ListFile(string inputPath) { List <string> result = new List <string>(); BLanguageSet languageSet = LanguageFileConverter.LoadLanguageFile(inputPath); result.Add($"File: {inputPath}"); result.Add($"Language: {languageSet.LanguageKey}"); languageSet.Itens.ForEach(item => result.Add($"{item.Key} : {item.Value}")); return(result); }
public static void Save() { try { CheckInstance(); foreach (BLanguageSet item in LanguageSets) { LanguageFileConverter.SaveLanguageFile(item, instance.strBasePath); } } catch (Exception) { throw; } }
public static void GenerateTestFiles() { BLanguageSet objAuxTest; try { if (!Directory.Exists(Path.Combine(".", "locales"))) { Directory.CreateDirectory(Path.Combine(".", "locales")); } if (File.Exists(Path.Combine(".", "locales", "pt-br.json"))) { File.Delete(Path.Combine(".", "locales", "pt-br.json")); } if (File.Exists(Path.Combine(".", "locales", "en-us.json"))) { File.Delete(Path.Combine(".", "locales", "en-us.json")); } if (!File.Exists(Path.Combine(".", "locales", "en-us.json"))) { objAuxTest = new BLanguageSet(new List <BLanguageItem>() { new BLanguageItem("group_one.text_one", "Test text one, translate"), new BLanguageItem("group_one.text_two", "Test text two, translate"), new BLanguageItem("group_one.text_three", "Test text three, translate"), new BLanguageItem("group_one.text_four", "Test text four, translate"), new BLanguageItem("group_two.text_five", "Test text five, translate"), new BLanguageItem("group_two.text_six", "Test text six, translate"), new BLanguageItem("group_two.text_seven", "Test text seven, translate"), new BLanguageItem("group_two.text_eight", "Test text eight, translate"), new BLanguageItem("group_two.sub_group.text_nine", "Test text nine, translate"), }, "en-us"); LanguageFileConverter.SaveLanguageFile(objAuxTest, Path.Combine(".", "locales")); } } catch (Exception) { throw; } }
public string TranslateFile(string inputPath, string targetLanguage) { string translatedText = ""; BLanguageSet languageSet = LanguageFileConverter.LoadLanguageFile(inputPath); BLanguageSet resultLangageSet; List <BLanguageItem> bLanguageItens = new List <BLanguageItem>(); JArray jsonRsult; languageSet.Itens.ForEach(async item => { translatedText = getTranslationAsync(item.Value, languageSet.LanguageKey, targetLanguage).Result; jsonRsult = JArray.Parse(translatedText); bLanguageItens.Add(new BLanguageItem(item.Key, jsonRsult[0][0][0].ToString())); }); resultLangageSet = new BLanguageSet(bLanguageItens, targetLanguage); LanguageFileConverter.SaveLanguageFile(resultLangageSet, Path.GetDirectoryName(inputPath)); return(Path.Combine(Path.GetDirectoryName(inputPath), targetLanguage + ".json")); }