/// <summary> /// Create a dictionary from a list of localization files /// </summary> /// <param name="basePath">Base path to localization files</param> /// <param name="localizationFiles">List of paths to localization files</param> /// <param name="newDefaultLanguage">default language of the new dictionary</param> /// <param name="newCurrentLanguage">current language of the new dictionary</param> /// <returns></returns> public static DictionaryI18n ReadFromFileList(string basePath, IEnumerable <string> localizationFiles, string newDefaultLanguage, string newCurrentLanguage) { DictionaryI18n finalDict = null; DictionaryI18n partialDict; foreach (string file in localizationFiles) { // The partial dicts are created without default and current language and after loading // all dict the default and current language will be stablished partialDict = LocalizationRead.ReadFromFilePath(basePath + file, null, null); if (finalDict == null) { finalDict = partialDict; } else { finalDict.AddRaw(partialDict); } } if (finalDict != null) { finalDict.setDefaultLanguage(newDefaultLanguage); finalDict.setCurrentLanguage(newCurrentLanguage); } return(finalDict); }
public void TestSerializedDictionariesJoinsCorrectly() { Dictionary <string, List <string> > dictionaries = sut.SerializeMultiple(); DictionaryI18n partialLocalizationDict; DictionaryI18n localizationDict = null; foreach (string language in dictionaries.Keys) { partialLocalizationDict = new DictionaryI18n(dictionaries[language].ToArray(), language, language); if (localizationDict == null) { localizationDict = partialLocalizationDict; } else { localizationDict.AddRaw(partialLocalizationDict); } } sut.setDefaultLanguage(DictionaryI18n.DEFAULT_LANG); localizationDict.setDefaultLanguage(DictionaryI18n.DEFAULT_LANG); sut.flushRaw(); localizationDict.flushRaw(); // Compare languages for (int langPos = 0; langPos < localizationDict.getLanguages().Length; langPos++) { if (localizationDict.getLanguages()[langPos] != sut.getLanguages()[langPos]) { Assert.Fail(new StringBuilder() .Append("Languages position don't match: Position:") .Append(langPos) .Append(" SourceLang:") .Append(sut.getLanguages()[langPos]) .Append(" TargetLang:") .Append(localizationDict.getLanguages()[langPos]) .ToString()); } sut.setCurrentLanguage(localizationDict.getLanguages()[langPos]); localizationDict.setCurrentLanguage(localizationDict.getLanguages()[langPos]); } }