public static LocalizationDictionary CreateDictionary(string baseName, string objectName) { string culture = Thread.CurrentThread.CurrentUICulture.Name; string fileName = String.Format("Pergh.{0}.{1}.txt", objectName, culture); LocalizationDictionary dictionary = ((LocalizationDictionary)(HttpRuntime.Cache[fileName])); if (dictionary == null) { dictionary = new LocalizationDictionary(); string[] files = null; Stream s = CreateDictionaryStream(culture, baseName, objectName, out files); if ((s == null) && culture.Contains("-")) { culture = culture.Substring(0, culture.IndexOf("-")); s = CreateDictionaryStream(culture, baseName, objectName, out files); } if (s != null) { PopulateDictionary(dictionary, new StreamReader(s).ReadToEnd()); s.Close(); } CacheDependency dependency = null; if (files != null) { dependency = new CacheDependency(files); } HttpRuntime.Cache.Insert(fileName, dictionary, dependency); } return(dictionary); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //Debug.Log("draw"); Rect titlerect = new Rect(position.x, position.y, position.width / 3f, position.height); Rect dictrect = new Rect(position.x + position.width / 3f, position.y, position.width / 3f, position.height); Rect keyrect = new Rect(position.x + position.width * 2f / 3f, position.y, position.width / 3f, position.height); EditorGUI.LabelField(titlerect, property.name); EditorGUI.PropertyField(dictrect, property.FindPropertyRelative("Dictionary"), GUIContent.none); LocalizationDictionary dict = property.FindPropertyRelative("Dictionary").objectReferenceValue as LocalizationDictionary; if (dict != null) { if (!dict.Keys.Contains(property.FindPropertyRelative("Key").stringValue)) { property.FindPropertyRelative("Key").stringValue = dict.Keys[0]; } int index = dict.Keys.IndexOf(property.FindPropertyRelative("Key").stringValue); index = EditorGUI.Popup(keyrect, index, dict.Keys.ToArray()); property.FindPropertyRelative("Key").stringValue = dict.localisedStrings[index].key; } property.serializedObject.ApplyModifiedProperties(); }
public void ReadsIncludedDictionaries() { var resolver = Mock.Of<IResolver>(t => t.Open("file.xml") == ToStream( @"<?xml version=""1.0""?> <?mios-localization include=""second.xml"" prefix=""pfx""?> <dictionary> <key id=""first""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> </dictionary>") && t.Open("second.xml") == ToStream( @"<?xml version=""1.0""?> <dictionary> <key id=""second""> <val for=""fi"">ghi</val> <val for=""sv-fi"">jkl</val> </key> </dictionary>") ); Mock.Get(resolver).Setup(t => t.Combine(It.IsAny<string>(), It.IsAny<string>())).Returns<string, string>((a, b) => b); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver }.Read(dictionary); Assert.Equal("abc", dictionary["fi", "first"]); Assert.Equal("ghi", dictionary["fi", "pfxsecond"]); }
public void ReadsIncludedDictionaries() { var resolver = Mock.Of <IResolver>(t => t.Open("file.xml") == ToStream( @"<?xml version=""1.0""?> <?mios-localization include=""second.xml"" prefix=""pfx""?> <dictionary> <key id=""first""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> </dictionary>") && t.Open("second.xml") == ToStream( @"<?xml version=""1.0""?> <dictionary> <key id=""second""> <val for=""fi"">ghi</val> <val for=""sv-fi"">jkl</val> </key> </dictionary>") ); Mock.Get(resolver).Setup(t => t.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns <string, string>((a, b) => b); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver }.Read(dictionary); Assert.Equal("abc", dictionary["fi", "first"]); Assert.Equal("ghi", dictionary["fi", "pfxsecond"]); }
public void ReadsMultipleKeyAndValues() { var resolver = Mock.Of <IResolver>(t => t.Open(It.IsAny <string>()) == ToStream( @"<?xml version=""1.0""?> <dictionary> <key id=""xyz""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> <key id=""pqr""> <val for=""fi"">123</val> <val for=""en"">456</val> </key> </dictionary>") ); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver }.Read(dictionary); Assert.Equal("abc", dictionary["fi", "xyz"]); Assert.Equal("def", dictionary["sv-fi", "xyz"]); Assert.Equal("123", dictionary["fi", "pqr"]); Assert.Equal("456", dictionary["en", "pqr"]); }
public void ShouldReturnEmptyLocalizedStringIfKeyIsNull() { var dictionary = new LocalizationDictionary(); var t = new FallbackDictionaryLocalizer(dictionary, "sv-se"); Assert.Null(t.Localize(null).Localization); }
public void ShouldReturnValueFromDefaultLocalizerIfNotFound() { var dictionary = new LocalizationDictionary(); var t = new FallbackDictionaryLocalizer(dictionary, "sv-se") { DefaultLocalizer = (k, p) => new LocalizedString(k, "default") }; Assert.Equal("default", t.Localize("k")); }
public void ReadsIncludedDictionariesOnlyIfSpecified() { var resolver = Mock.Of <IResolver>(t => t.Open("file.xml") == ToStream( @"<?xml version=""1.0""?> <?mios-localization include=""second.xml""?> <dictionary> <key id=""first""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> </dictionary>") && t.Open("second.xml") == ToStream(@"<?xml version=""1.0""?><dictionary/>") ); Mock.Get(resolver).Setup(t => t.Combine(It.IsAny <string>(), It.IsAny <string>())).Returns <string, string>((a, b) => b); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver, Recursive = false }.Read(dictionary); Mock.Get(resolver).Verify(t => t.Open("second.xml"), Times.Never()); }
public void WritesKeysToStream() { var dic = new LocalizationDictionary(); dic["fi", "first"] = "ensimmäinen"; dic["sv", "first"] = "första"; dic["sv-fi", "first"] = "först"; var writer = new StringWriter(); new XmlLocalizationWriter().Write(dic, writer); var doc = XDocument.Parse(writer.ToString()); Assert.Equal("dictionary", doc.Root.Name); var e = doc.Root.Element("key"); Assert.Equal("first", e.Attribute("id").Value); var elements = e.Elements("val").ToArray(); Assert.Equal("fi", elements[0].Attribute("for").Value); Assert.Equal("ensimmäinen", elements[0].Value); Assert.Equal("sv", elements[1].Attribute("for").Value); Assert.Equal("första", elements[1].Value); Assert.Equal("sv-fi", elements[2].Attribute("for").Value); Assert.Equal("först", elements[2].Value); }
public FallbackDictionaryLocalizer(LocalizationDictionary dictionary, params string[] locales) { if(dictionary == null) throw new ArgumentNullException("dictionary"); if(locales == null) throw new ArgumentNullException("locales"); DefaultLocalizer = NullLocalizer.Instance; this.dictionary = dictionary; this.locales = locales; }
public void WritesIncludesToStream() { var dic = new LocalizationDictionary { Includes = { new LocalizationDictionary.Include { Path = "second.xml", Prefix = "pfx" }, new LocalizationDictionary.Include { Path = "third.xml" } } }; dic["fi", "first"] = "ensimmäinen"; var writer = new StringWriter(); new XmlLocalizationWriter().Write(dic, writer); var doc = XDocument.Parse(writer.ToString()); var pi = doc.Nodes().OfType <XProcessingInstruction>().First(); Assert.Equal("mios-localization", pi.Target); Assert.Equal("include=\"second.xml\" prefix=\"pfx\"", pi.Data); pi = doc.Nodes().OfType <XProcessingInstruction>().Skip(1).First(); Assert.Equal("mios-localization", pi.Target); Assert.Equal("include=\"third.xml\"", pi.Data); }
private void ChangeLanguage(LocalizationDictionary value) { if (value != null) { LocalizationService.Current.ChangeLanguage(value); } }
public void ShouldReturnFallbackLocalizationIfFullLocaleNotFound() { var dictionary = new LocalizationDictionary { {"sv","k","Fallback"} }; var t = new FallbackDictionaryLocalizer(dictionary, "sv-se","sv"); Assert.Equal("Fallback", t.Localize("k")); }
public void ShouldReturnLocalizationFromDictionary() { var dictionary = new LocalizationDictionary { {"sv-se","k","Key"} }; var t = new FallbackDictionaryLocalizer(dictionary, "sv-se"); Assert.Equal("Key", t.Localize("k")); }
public void ReadsRelativeDictionaries() { var resolver = Mock.Of <IResolver>(t => t.Combine("a/file.xml", "../b/second.xml") == "b/second.xml" && t.Open("a/file.xml") == ToStream( @"<?xml version=""1.0""?> <?mios-localization include=""../b/second.xml""?> <dictionary> <key id=""first""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> </dictionary>") && t.Open("b/second.xml") == ToStream( @"<?xml version=""1.0""?> <dictionary> <key id=""second""> <val for=""fi"">ghi</val> <val for=""sv-fi"">jkl</val> </key> </dictionary>") ); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("a/file.xml") { Resolver = resolver }.Read(dictionary); Assert.Equal("abc", dictionary["fi", "first"]); Assert.Equal("ghi", dictionary["fi", "second"]); }
public void RemapsLocaleStrings() { const string source = @"<?xml version=""1.0""?><page><key id=""first""><fi>ensimmäinen</fi><sv>första</sv><svFI>först</svFI></key></page>"; var dic = new LocalizationDictionary(); new LegacyXmlLocalizationReader().Read(new StringReader(source), dic); Assert.Equal("först", dic["sv-fi", "first"]); }
private void CleanupAndSaveDictionary(string path) { var result = new LocalizationDictionary(); LoadDictionary(result, path); MergeDictionaries(result, dictionary); SaveDictionary(result, path); }
public void AddPerservesKeyOrder() { var dictionary = new LocalizationDictionary(); dictionary["fi-fi", "UPPERCASE"] = "true"; dictionary["sv-se", "lowercase"] = "true"; dictionary["fi-se", "UPPERCASE"] = "true"; var keys = dictionary.Keys.ToArray(); Assert.Equal(new [] { "UPPERCASE", "lowercase"}, keys.ToArray()); }
private static void SaveDictionary(LocalizationDictionary dictionary, string path) { using (new DirectoryChanger(The.Workspace.AssetsDirectory)) { using (var stream = new FileStream(path, FileMode.Create)) { dictionary.WriteToStream(CreateSerializer(), stream); } } }
public LocalizationDictionary Load(int index) { var newData = new LocalizationDictionary(AvailableLanguages[index]); JsonUtility.FromJsonOverwrite(GetJSONStringFromFile(AvailableLanguages[index]), newData); return(newData); }
public void AddPerservesKeyNameCase() { var dictionary = new LocalizationDictionary(); dictionary["fi-fi", "UPPERCASE"] = "true"; dictionary["fi-fi", "lowercase"] = "true"; var keys = dictionary.Keys.ToArray(); Assert.Contains("UPPERCASE", keys); Assert.Contains("lowercase", keys); }
private static void WriteIncludes(LocalizationDictionary dictionary, XmlWriter writer) { foreach(var include in dictionary.Includes) { var data = "include=\""+include.Path+"\""; if(!String.IsNullOrEmpty(include.Prefix)) { data += " prefix=\""+include.Prefix+"\""; } writer.WriteProcessingInstruction("mios-localization", data); } }
private static void LoadDictionary(LocalizationDictionary dictionary, string path) { if (AssetBundle.Current.FileExists(path)) { using (var stream = AssetBundle.Current.OpenFile(path)) { dictionary.ReadFromStream(CreateSerializer(), stream); } } }
public void ShouldReturnFallbackLocalizationIfFullLocaleNotFound() { var dictionary = new LocalizationDictionary { { "sv", "k", "Fallback" } }; var t = new FallbackDictionaryLocalizer(dictionary, "sv-se", "sv"); Assert.Equal("Fallback", t.Localize("k")); }
public void ExtractDictionary() { dictionary = new LocalizationDictionary(); ExtractTexts(); foreach (var name in GetFileNames()) { CleanupAndSaveDictionary(Path.Combine(GetDictionariesDirectory(), name)); } }
public void ShouldReturnLocalizationFromDictionary() { var dictionary = new LocalizationDictionary { { "sv-se", "k", "Key" } }; var t = new FallbackDictionaryLocalizer(dictionary, "sv-se"); Assert.Equal("Key", t.Localize("k")); }
public LocalizationDictionary Get(LocalizationDictionary request) { LocalizationRepository repository = GetRepository(); if (request.Locale == null) return null; LocalizationCollectionEntity collection = repository.Read(request.Locale); return TranslateToResponse(collection); }
public static string GetLabelFromLocalizationList(LocalizationDictionary localizationList, string name) { foreach (var obj in localizationList.LocalizationData) { if (obj.Key.Equals(name)) { return obj.Value; } } return name; }
public void AddPerservesKeyOrder() { var dictionary = new LocalizationDictionary(); dictionary["fi-fi", "UPPERCASE"] = "true"; dictionary["sv-se", "lowercase"] = "true"; dictionary["fi-se", "UPPERCASE"] = "true"; var keys = dictionary.Keys.ToArray(); Assert.Equal(new [] { "UPPERCASE", "lowercase" }, keys.ToArray()); }
private static void LoadDictionary(LocalizationDictionary dictionary, string path) { using (new DirectoryChanger(The.Workspace.AssetsDirectory)) { if (File.Exists(path)) { using (var stream = new FileStream(path, FileMode.Open)) { dictionary.ReadFromStream(CreateSerializer(), stream); } } } }
public Task <ILocalizationDictionary> GetLocalizationDictionary() { ILocalizationDictionary dic = new LocalizationDictionary(Sources[0].CultureInfo, Sources[0].SourceName, new Dictionary <string, string>() { { "name", "Name" } } ); return(Task.FromResult(dic)); }
private void CleanupAndSaveDictionary(string path) { var result = new LocalizationDictionary(); LoadDictionary(result, path); var addContext = ShouldAddContextToLocalizedDictionary() || path.EndsWith(GetDefaultFileName(), StringComparison.OrdinalIgnoreCase); MergeDictionaries(result, dictionary, addContext); SaveDictionary(result, path); }
private static void WriteIncludes(LocalizationDictionary dictionary, XmlWriter writer) { foreach (var include in dictionary.Includes) { var data = "include=\"" + include.Path + "\""; if (!String.IsNullOrEmpty(include.Prefix)) { data += " prefix=\"" + include.Prefix + "\""; } writer.WriteProcessingInstruction("mios-localization", data); } }
/// <summary> /// Builds an <see cref="JsonLocalizationDictionaryBuilder" /> from given json string. /// </summary> /// <param name="jsonString">Json string</param> public static ILocalizationDictionary BuildFromJsonString(string jsonString) { JsonLocalizationFile jsonFile; try { jsonFile = JsonConvert.DeserializeObject <JsonLocalizationFile>( jsonString, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); } catch (JsonException ex) { throw new AbpException("Can not parse json string. " + ex.Message); } var cultureCode = jsonFile.Culture; if (string.IsNullOrEmpty(cultureCode)) { throw new AbpException("Culture is empty in language json file."); } var dictionary = new LocalizationDictionary(cultureCode); var dublicateNames = new List <string>(); foreach (var item in jsonFile.Texts) { if (string.IsNullOrEmpty(item.Key)) { throw new AbpException("The key is empty in given json string."); } if (dictionary.GetOrNull(item.Key) != null) { dublicateNames.Add(item.Key); } dictionary[item.Key] = new LocalString(item.Key, item.Value.NormalizeLineEndings()); } if (dublicateNames.Count > 0) { throw new AbpException( "A dictionary can not contain same key twice. There are some duplicated names: " + dublicateNames.JoinAsString(", ")); } return(dictionary); }
private static void PopulateDictionary(LocalizationDictionary dictionary, string text) { Match m = TokenRegex.Match(text); while (m.Success) { string token = m.Groups[1].Value; if (token == m.Groups[3].Value) { dictionary[token] = m.Groups[2].Value; } m = m.NextMatch(); } }
public void WritesKeysToStream() { var dic = new LocalizationDictionary(); dic["fi", "first"] = "ensimmäinen"; dic["sv", "first"] = "första"; dic["sv-fi", "first"] = "först"; var writer = new StringWriter(); new LegacyXmlLocalizationWriter().Write(dic, writer); var doc = XDocument.Parse(writer.ToString()); var e = doc.Root.Element("key"); Assert.Equal("first", e.Attribute("id").Value); Assert.Equal("ensimmäinen", e.Element("fi").Value); Assert.Equal("första", e.Element("sv").Value); Assert.Equal("först", e.Element("svFI").Value); }
public FallbackDictionaryLocalizer(LocalizationDictionary dictionary, params string[] locales) { if (dictionary == null) { throw new ArgumentNullException("dictionary"); } if (locales == null) { throw new ArgumentNullException("locales"); } DefaultLocalizer = NullLocalizer.Instance; this.dictionary = dictionary; this.locales = locales; }
public MainWindowViewModel() { var a = LocalizationService.RegisteredPacks; var cultures = a.Keys; foreach (var culture in cultures) { var pack = LocalizationDictionary.GetResources(culture); Cultures.Add(pack); CultureMenus.Add(new MenuItem() { Header = $"{pack.EnglishName} ({pack.CultureName})", Tag = pack }); } }
private static void MergeDictionaries(LocalizationDictionary current, LocalizationDictionary modified, bool addContext) { int added = 0; int deleted = 0; int updated = 0; foreach (var key in modified.Keys.ToList()) { if (!current.ContainsKey(key)) { Logger.Write("+ " + key); added++; current[key] = new LocalizationEntry() { Text = modified[key].Text, Context = modified[key].Context }; } else { var currentEntry = current[key]; var newEntry = modified[key]; if (currentEntry.Context != newEntry.Context) { Logger.Write("Context updated for: " + key); updated++; currentEntry.Context = newEntry.Context; } } if (!addContext) { current[key].Context = ""; } } foreach (var key in current.Keys.ToList()) { if (!modified.ContainsKey(key) && !LocalizationDictionary.IsComment(key)) { Logger.Write("- " + key); deleted++; current.Remove(key); } } Logger.Write("Added {0}\nDeleted {1}\nContext updated {2}", added, deleted, updated); }
public void WritesIncludesToStream() { var dic = new LocalizationDictionary { Includes = { new LocalizationDictionary.Include { Path = "second.xml", Prefix = "pfx" }, new LocalizationDictionary.Include { Path = "third.xml" } } }; dic["fi", "first"] = "ensimmäinen"; var writer = new StringWriter(); new XmlLocalizationWriter().Write(dic, writer); var doc = XDocument.Parse(writer.ToString()); var pi = doc.Nodes().OfType<XProcessingInstruction>().First(); Assert.Equal("mios-localization", pi.Target); Assert.Equal("include=\"second.xml\" prefix=\"pfx\"", pi.Data); pi = doc.Nodes().OfType<XProcessingInstruction>().Skip(1).First(); Assert.Equal("mios-localization", pi.Target); Assert.Equal("include=\"third.xml\"", pi.Data); }
public void RecordsIncludes() { var resolver = Mock.Of<IResolver>(t => t.Open("file.xml") == ToStream( @"<?xml version=""1.0"" encoding=""utf-8""?> <?mios-localization include=""second.xml""?> <dictionary> <key id=""test""> <val for=""fi""><![CDATA[Testaus]]></val> <val for=""sv""><![CDATA[Testning]]></val> </key> </dictionary>") ); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver, Recursive = false }.Read(dictionary); Assert.Contains(new LocalizationDictionary.Include { Path = "second.xml" }, dictionary.Includes); }
public static void ApplyLanguagingToLabels(List<INameLabel> responseList) { //Add l18n here AuthService authService = new AuthService(); var language = "nl-nl"; try { var currentUser = authService.Get(new CurrentUserAuthRequest()); language = currentUser.Language; } catch (Exception) { } LocalizationDictionary request = new LocalizationDictionary(); request.Locale = language; LocalizationDictionary localizationList = _client.Get<LocalizationDictionary>(request); foreach (var obj in responseList) { obj.Label = GetLabelFromLocalizationList(localizationList, "_" + obj.Name + "_"); } }
public static string GetL18nLabel(string name) { name = "_" + name + "_"; //Add l18n here AuthService authService = new AuthService(); var language = "nl-nl"; try { var currentUser = authService.Get(new CurrentUserAuthRequest()); language = currentUser.Language; } catch (Exception) { } LocalizationDictionary request = new LocalizationDictionary(); request.LocalizationData.Add(new LocalizationItem() { Key = name }); request.Locale = language; LocalizationDictionary localizationList = _client.Get<LocalizationDictionary>(request); return GetLabelFromLocalizationList(localizationList, name); }
public void ReadsIncludedDictionariesOnlyIfSpecified() { var resolver = Mock.Of<IResolver>(t => t.Open("file.xml") == ToStream( @"<?xml version=""1.0""?> <?mios-localization include=""second.xml""?> <dictionary> <key id=""first""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> </dictionary>") && t.Open("second.xml") == ToStream(@"<?xml version=""1.0""?><dictionary/>") ); Mock.Get(resolver).Setup(t => t.Combine(It.IsAny<string>(), It.IsAny<string>())).Returns<string, string>((a, b) => b); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver, Recursive = false }.Read(dictionary); Mock.Get(resolver).Verify(t => t.Open("second.xml"), Times.Never()); }
public void RemapsLocaleStrings() { const string source = @"<?xml version=""1.0""?><page><key id=""first""><fi>ensimmäinen</fi><sv>första</sv><svFI>först</svFI></key></page>"; var dic = new LocalizationDictionary(); new LegacyXmlLocalizationReader().Read(new StringReader(source),dic); Assert.Equal("först", dic["sv-fi", "first"]); }
public void ReadsRelativeDictionaries() { var resolver = Mock.Of<IResolver>(t => t.Combine("a/file.xml","../b/second.xml") == "b/second.xml" && t.Open("a/file.xml") == ToStream( @"<?xml version=""1.0""?> <?mios-localization include=""../b/second.xml""?> <dictionary> <key id=""first""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> </dictionary>") && t.Open("b/second.xml") == ToStream( @"<?xml version=""1.0""?> <dictionary> <key id=""second""> <val for=""fi"">ghi</val> <val for=""sv-fi"">jkl</val> </key> </dictionary>") ); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("a/file.xml") { Resolver = resolver }.Read(dictionary); Assert.Equal("abc", dictionary["fi", "first"]); Assert.Equal("ghi", dictionary["fi", "second"]); }
private static LocalizationCollectionEntity TranslateToEntity(LocalizationDictionary request) { LocalizationCollectionEntity response = request.TranslateTo<LocalizationCollectionEntity>(); request.LocalizationData.ForEach(x => response.LocalizationItems.Add(x.TranslateTo<LocalizationEntity>())); return response; }
public LocalizationDictionary Put(LocalizationDictionary request) { return PutPostLocalizationDictionary(request); }
public void Delete(LocalizationDictionary request) { var repository = GetRepository(); repository.Delete(request.Locale); }
public void ReadsCompactFiles() { var resolver = Mock.Of<IResolver>(t => t.Open(It.IsAny<string>()) == ToStream( @"<?xml version=""1.0""?> <dictionary> <key id=""xyz""><val for=""fi""></val></key> <key id=""pqr""><val for=""fi""></val></key> </dictionary>") ); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver }.Read(dictionary); Assert.Contains("xyz", dictionary.Keys); Assert.Contains("pqr", dictionary.Keys); Assert.Equal("", dictionary["fi", "xyz"]); Assert.Equal("", dictionary["fi", "pqr"]); }
public void SkipsUnknownElements() { var resolver = Mock.Of<IResolver>(t => t.Open(It.IsAny<string>()) == ToStream( @"<?xml version=""1.0""?> <dictionary> <garbage/> <key id=""xyz""> <random>This is text</random> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> </dictionary>") ); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver }.Read(dictionary); Assert.Equal("abc", dictionary["fi", "xyz"]); Assert.Equal("def", dictionary["sv-fi", "xyz"]); }
public void ReadsMultipleKeyAndValues() { var resolver = Mock.Of<IResolver>(t => t.Open(It.IsAny<string>()) == ToStream( @"<?xml version=""1.0""?> <dictionary> <key id=""xyz""> <val for=""fi"">abc</val> <val for=""sv-fi"">def</val> </key> <key id=""pqr""> <val for=""fi"">123</val> <val for=""en"">456</val> </key> </dictionary>") ); var dictionary = new LocalizationDictionary(); new XmlLocalizationReader("file.xml") { Resolver = resolver }.Read(dictionary); Assert.Equal("abc", dictionary["fi", "xyz"]); Assert.Equal("def", dictionary["sv-fi", "xyz"]); Assert.Equal("123", dictionary["fi", "pqr"]); Assert.Equal("456", dictionary["en", "pqr"]); }
private LocalizationDictionary PutPostLocalizationDictionary(LocalizationDictionary request) { LocalizationCollectionEntity collection = TranslateToEntity(request); LocalizationRepository repository = GetRepository(); return TranslateToResponse(repository.Create(collection)); }