public void EnsureDescriptions(CldrLocale provider) { if (_descriptionsProvider == provider || provider == null) { return; } _descriptionsProvider = provider; var names = provider.LocaleDisplayNames.TerritoryNames; var snames = provider.LocaleDisplayNames.SubdivisionNames; foreach (Territory ter in _territories.Values) { if (names.TryGetValue(ter, out string name) || snames != null && snames.TryGetValue(ter, out name)) { ter.Description = name; } } foreach (LanguageInfo info in _localeInfo.Values) { info.Locale?.ResolveDescription(provider); } }
public override CldrJson PrepareForMerging(CldrLocale locale, JObject obj) { var dataProperty = obj.SelectToken("main.*.*")?.Parent; if (dataProperty == null) return null; var data = new JObject((JProperty)dataProperty); return new CldrJson(locale, data); }
public void Equals_SlightlyDifferent_False() { var l = new CldrLocale("a", "b", "c", "d"); l.Should().NotBe(new CldrLocale("a", "b", "c", "e")); l.Should().NotBe(new CldrLocale("a", "b", "d", "d")); l.Should().NotBe(new CldrLocale("a", "d", "c", "d")); l.Should().NotBe(new CldrLocale("d", "b", "c", "d")); l.Should().Be(new CldrLocale("a", "b", "c", "d")); }
public override CldrJson PrepareForMerging(CldrLocale locale, JObject obj) { var dataProperty = obj.SelectToken("main.*.*")?.Parent; if (dataProperty == null) { return(null); } var data = new JObject((JProperty)dataProperty); return(new CldrJson(locale, data)); }
private CldrLocale TryLoadLanguage(string name, CldrLocale parent) { XmlReader reader = TryOpenXmlFile("main", name); if (reader == null) { return(null); } CldrLocale doc; try { doc = new CldrLocale(this, parent, ResolveLanguage(name)); doc.LoadMain(reader); } finally { reader.Dispose(); } if ((LoadOptions & CldrLoadOptions.Rbnf) != 0) { reader = TryOpenXmlFile("rbnf", name); if (reader != null) { try { doc.LoadMisc(reader, "rbnf"); } finally { reader.Dispose(); } } } if ((LoadOptions & CldrLoadOptions.Subdivision) != 0) { reader = TryOpenXmlFile("subdivisions", name); if (reader != null) { try { doc.LocaleDisplayNames.LoadMisc(reader, "subdivisions"); } finally { reader.Dispose(); } } } doc.Loaded(); if (_descriptionsProvider != null) { doc.ResolveDescription(_descriptionsProvider); } return(doc); }
public CldrLocale GetLocale(string localeName) { LanguageInfo localeInfo = FindLanguage(ref localeName); if (localeInfo?.Locale != null) { return(localeInfo.Locale); } CldrLocale rootLocale = GetLocaleInfo("root").Locale; if (rootLocale == null) { rootLocale = TryLoadLanguage("root", null); if (localeName.Equals("root", StringComparison.OrdinalIgnoreCase)) { return(rootLocale); } } CldrLocale parentLocale = null; if (localeInfo == null) { localeInfo = GetLocaleInfo(localeName); } LanguageInfo parentInfo = localeInfo.Parent; string parentName = localeName; while (parentInfo == null) { int idx = parentName.LastIndexOf('_'); if (idx > 0) { parentName = localeName.Substring(0, idx); parentInfo = FindLanguage(ref parentName); } else { break; } } if (parentInfo != null) { parentLocale = GetLocale(parentInfo.Code); } return(TryLoadLanguage(localeName, parentLocale ?? rootLocale)); }
public void EnsureAllLocalesLoaded() { if (_allLoaded != null) { return; } foreach (string name in GetAllLocaleNames()) { GetLocale(name); } Dictionary <CldrLocale, List <CldrLocale> > map = new Dictionary <CldrLocale, List <CldrLocale> >(); List <CldrLocale> list = new List <CldrLocale>(_localeInfo.Count); foreach (LanguageInfo info in _localeInfo.Values) { CldrLocale locale = info.Locale; if (locale != null) { list.Add(locale); var parent = locale.Parent; if (parent != null) { map.AddGroup(parent, locale); } locale.Children = CldrLocale.EmptyArray; } else { Debug.WriteLine("W+" + info.Code); } } _allLoaded = list.ToArray(); foreach (var pair in map) { pair.Key.Children = pair.Value.ToArray(); } }
/// <summary> /// Returns a normalized <see cref="CldrJson"/> object, ready to be merged /// into <see cref="CldrTree"/>. /// </summary> /// <remarks> /// Note that the specified JSON object does not have metadata anymore. /// What is more, the subsetting step (3rd) might have removed some of its /// subtrees. It cannot be assumed to be valid against this parser's schema anymore. /// However, it is assumed that this JSON is the previously valid JSON, /// but with some of its descendants removed. /// </remarks> public virtual CldrJson PrepareForMerging(CldrLocale locale, JObject obj) { return(new CldrJson(locale, obj)); // by default no modifications }
public void MediumUSFormatTest() { var locale = new CldrLocale("en"); Assert.Equal("MMM d, y", _data.GetValue(_mediumDatePath, locale)); }
public void FullUSFormatTest() { var locale = new CldrLocale("en"); Assert.Equal("EEEE, MMMM d, y", _data.GetValue(_fullDatePath, locale)); }
public void MediumAUFormatTest() { var locale = new CldrLocale("en", null, "AU"); Assert.Equal("d MMM y", _data.GetValue(_mediumDatePath, locale)); }
public void ShortAUFormatTest() { var locale = new CldrLocale("en", null, "AU"); Assert.Equal("d/M/yy", _data.GetValue(_shortDatePath, locale)); }
public void FullAUFormatTest() { var locale = new CldrLocale("en", null, "AU"); Assert.Equal("EEEE, d MMMM y", _data.GetValue(_fullDatePath, locale)); }
public CldrJson(CldrLocale locale, JObject data) { this.Locale = locale; this.Data = data; }
/// <summary> /// Returns a normalized <see cref="CldrJson"/> object, ready to be merged /// into <see cref="CldrTree"/>. /// </summary> /// <remarks> /// Note that the specified JSON object does not have metadata anymore. /// What is more, the subsetting step (3rd) might have removed some of its /// subtrees. It cannot be assumed to be valid against this parser's schema anymore. /// However, it is assumed that this JSON is the previously valid JSON, /// but with some of its descendants removed. /// </remarks> public virtual CldrJson PrepareForMerging(CldrLocale locale, JObject obj) { return new CldrJson(locale, obj); // by default no modifications }
public void ShortUSFormatTest() { var locale = new CldrLocale("en"); Assert.Equal("M/d/yy", _data.GetValue(_shortDatePath, locale)); }