public override IList <UiListItem> GetUiListCompareWholeItems(ISet <ULocale> localeSet, IComparer <UiListItem> comparer) { DisplayContext capContext = GetContext(DisplayContextType.Capitalization); List <UiListItem> result = new List <UiListItem>(); IDictionary <ULocale, ISet <ULocale> > baseToLocales = new Dictionary <ULocale, ISet <ULocale> >(); ULocale.Builder builder = new ULocale.Builder(); foreach (ULocale locOriginal in localeSet) { builder.SetLocale(locOriginal); // verify well-formed. We do this here so that we consistently throw exception ULocale loc = ULocale.AddLikelySubtags(locOriginal); ULocale @base = new ULocale(loc.GetLanguage()); ISet <ULocale> locales = baseToLocales.Get(@base); if (locales == null) { baseToLocales[@base] = locales = new HashSet <ULocale>(); } locales.Add(loc); } foreach (var entry in baseToLocales) { ULocale @base = entry.Key; ISet <ULocale> values = entry.Value; if (values.Count == 1) { ULocale locale = values.First(); result.Add(NewRow(ULocale.MinimizeSubtags(locale, ULocale.Minimize.FAVOR_SCRIPT), capContext)); } else { ISet <string> scripts = new HashSet <string>(); ISet <string> regions = new HashSet <string>(); // need the follow two steps to make sure that unusual scripts or regions are displayed ULocale maxBase = ULocale.AddLikelySubtags(@base); scripts.Add(maxBase.GetScript()); regions.Add(maxBase.GetCountry()); foreach (ULocale locale in values) { scripts.Add(locale.GetScript()); regions.Add(locale.GetCountry()); } bool hasScripts = scripts.Count > 1; bool hasRegions = regions.Count > 1; foreach (ULocale locale in values) { ULocale.Builder modified = builder.SetLocale(locale); if (!hasScripts) { modified.SetScript(""); } if (!hasRegions) { modified.SetRegion(""); } result.Add(NewRow(modified.Build(), capContext)); } } } result.Sort(comparer); return(result); }