Ejemplo n.º 1
0
        private UiListItem NewRow(UCultureInfo modified, Capitalization capitalization)
        {
#pragma warning disable 612, 618
            UCultureInfo minimized = UCultureInfo.MinimizeSubtags(modified, UCultureInfo.Minimize.FavorScript);
#pragma warning restore 612, 618
            string tempName            = modified.GetDisplayName(locale);
            bool   titlecase           = capitalization == Capitalization.UIListOrMenu;
            string nameInDisplayLocale =
                titlecase ? ToTitleWholeStringNoLowercase(locale, tempName) : tempName;
            tempName = modified.GetDisplayName(modified);
            string nameInSelf = capitalization ==
                                Capitalization.UIListOrMenu ?
                                ToTitleWholeStringNoLowercase(modified, tempName) : tempName;
            return(new UiListItem(minimized, modified, nameInDisplayLocale, nameInSelf));
        }
Ejemplo n.º 2
0
        public override IList <UiListItem> GetUiListCompareWholeItems(ICollection <UCultureInfo> cultures, IComparer <UiListItem> comparer)
        {
            Capitalization capContext = displayContextOptions.Capitalization;

            List <UiListItem> result = new List <UiListItem>();

            IDictionary <UCultureInfo, ISet <UCultureInfo> > baseToLocales = new Dictionary <UCultureInfo, ISet <UCultureInfo> >();
            UCultureInfoBuilder builder = new UCultureInfoBuilder();

            foreach (var locOriginal in cultures)
            {
                builder.SetCulture(locOriginal); // verify well-formed. We do this here so that we consistently throw exception
                UCultureInfo loc   = UCultureInfo.AddLikelySubtags(locOriginal);
                UCultureInfo @base = new UCultureInfo(loc.Language);
                if (!baseToLocales.TryGetValue(@base, out ISet <UCultureInfo> locales) || locales == null)
                {
                    baseToLocales[@base] = locales = new JCG.HashSet <UCultureInfo>(1);
                }
                locales.Add(loc);
            }
            foreach (var entry in baseToLocales)
            {
                UCultureInfo        @base  = entry.Key;
                ISet <UCultureInfo> values = entry.Value;
                if (values.Count == 1)
                {
                    UCultureInfo locale = values.First();
#pragma warning disable 612, 618
                    result.Add(NewRow(UCultureInfo.MinimizeSubtags(locale, UCultureInfo.Minimize.FavorScript), capContext));
#pragma warning restore 612, 618
                }
                else
                {
                    ISet <string> scripts = new JCG.HashSet <string>(values.Count + 1);
                    ISet <string> regions = new JCG.HashSet <string>(values.Count + 1);
                    // need the follow two steps to make sure that unusual scripts or regions are displayed
                    UCultureInfo maxBase = UCultureInfo.AddLikelySubtags(@base);
                    scripts.Add(maxBase.Script);
                    regions.Add(maxBase.Country);
                    foreach (UCultureInfo locale in values)
                    {
                        scripts.Add(locale.Script);
                        regions.Add(locale.Country);
                    }
                    bool hasScripts = scripts.Count > 1;
                    bool hasRegions = regions.Count > 1;
                    foreach (UCultureInfo locale in values)
                    {
                        UCultureInfoBuilder modified = builder.SetCulture(locale);
                        if (!hasScripts)
                        {
                            modified.SetScript("");
                        }
                        if (!hasRegions)
                        {
                            modified.SetRegion("");
                        }
                        result.Add(NewRow(modified.Build(), capContext));
                    }
                }
            }
            result.Sort(comparer);
            return(result);
        }