/// <summary> /// Returns an instance of <see cref="LocaleDisplayNames"/> that returns names formatted for the provided <paramref name="locale"/>, /// using the provided <paramref name="dialectHandling"/>. /// </summary> /// <param name="locale">The display locale.</param> /// <param name="dialectHandling">How to select names for locales.</param> /// <returns>A <see cref="LocaleDisplayNames"/> instance.</returns> /// <stable>ICU 4.4</stable> public static LocaleDisplayNames GetInstance(ULocale locale, DialectHandling dialectHandling) { LocaleDisplayNames result = null; if (FACTORY_DIALECTHANDLING != null) { try { result = (LocaleDisplayNames)FACTORY_DIALECTHANDLING.Invoke(null, new object[] { locale, dialectHandling }); } catch (TargetInvocationException) { // fall through } //catch (IllegalAccessException) //{ // // fall through //} } if (result == null) { result = new LastResortLocaleDisplayNames(locale, dialectHandling); } return(result); }
new public static LocaleDisplayNames GetInstance(ULocale locale, DialectHandling dialectHandling) { lock (cache) { return(cache.Get(locale, dialectHandling)); } }
internal LastResortLocaleDisplayNames(ULocale locale, DialectHandling dialectHandling) #pragma warning disable 612, 618 : base() #pragma warning restore 612, 618 { this.locale = locale; DisplayContext context = (dialectHandling == DialectHandling.DialectNames) ? DisplayContext.DialectNames : DisplayContext.StandardNames; this.contexts = new DisplayContext[] { context }; }
public LocaleDisplayNames Get(ULocale locale, DialectHandling dialectHandling) { if (!(dialectHandling == this.dialectHandling && DisplayContext.CapitalizationNone == this.capitalization && DisplayContext.LengthFull == this.nameLength && DisplayContext.Substitute == this.substituteHandling && locale.Equals(this.locale))) { this.locale = locale; this.dialectHandling = dialectHandling; this.capitalization = DisplayContext.CapitalizationNone; this.nameLength = DisplayContext.LengthFull; this.substituteHandling = DisplayContext.Substitute; this.cache = new LocaleDisplayNamesImpl(locale, dialectHandling); } return(cache); }
public override DialectHandling GetDialectHandling() { DialectHandling result = DialectHandling.STANDARD_NAMES; foreach (DisplayContext context in contexts) { if (context.Type() == DisplayContextType.DialectHandling) { if (context.Value() == (int)DisplayContext.DialectNames) { result = DialectHandling.DIALECT_NAMES; break; } } } return(result); }
public LocaleDisplayNames Get(ULocale locale, params DisplayContext[] contexts) { DialectHandling dialectHandlingIn = DialectHandling.STANDARD_NAMES; DisplayContext capitalizationIn = DisplayContext.CapitalizationNone; DisplayContext nameLengthIn = DisplayContext.LengthFull; DisplayContext substituteHandling = DisplayContext.Substitute; foreach (DisplayContext contextItem in contexts) { switch (contextItem.Type()) { case DisplayContextType.DialectHandling: dialectHandlingIn = (contextItem.Value() == DisplayContext.StandardNames.Value()) ? DialectHandling.STANDARD_NAMES : DialectHandling.DIALECT_NAMES; break; case DisplayContextType.Capitalization: capitalizationIn = contextItem; break; case DisplayContextType.DisplayLength: nameLengthIn = contextItem; break; case DisplayContextType.SubstituteHandling: substituteHandling = contextItem; break; default: break; } } if (!(dialectHandlingIn == this.dialectHandling && capitalizationIn == this.capitalization && nameLengthIn == this.nameLength && substituteHandling == this.substituteHandling && locale.Equals(this.locale))) { this.locale = locale; this.dialectHandling = dialectHandlingIn; this.capitalization = capitalizationIn; this.nameLength = nameLengthIn; this.substituteHandling = substituteHandling; this.cache = new LocaleDisplayNamesImpl(locale, contexts); } return(cache); }
/// <summary> /// Returns an instance of <see cref="CultureDisplayNames"/> that /// returns names formatted for the provided <paramref name="locale"/>, /// using the provided <paramref name="dialectHandling"/>. /// </summary> /// <param name="locale">The display locale.</param> /// <param name="dialectHandling">How to select names for locales.</param> /// <returns>A <see cref="CultureDisplayNames"/> instance.</returns> /// <draft>ICU 60</draft> public static CultureDisplayNames GetInstance(UCultureInfo locale, DialectHandling dialectHandling) { CultureDisplayNames result = null; var options = new DisplayContextOptions { DialectHandling = dialectHandling }.Freeze(); var culture = locale; //.ToUCultureInfo(); if (cultureDisplayNamesFactory != null) { result = cultureDisplayNamesFactory.GetCultureDisplayNames(culture, options); } if (result == null) { result = new LastResortCultureDisplayNames(culture, options); } return(result); }
public LocaleDisplayNames Get(ULocale locale, DialectHandling dialectHandling) { syncLock.EnterUpgradeableReadLock(); try { if (!(dialectHandling == this.dialectHandling && DisplayContext.CapitalizationNone == this.capitalization && DisplayContext.LengthFull == this.nameLength && DisplayContext.Substitute == this.substituteHandling && locale.Equals(this.locale))) { syncLock.EnterWriteLock(); try { if (!(dialectHandling == this.dialectHandling && DisplayContext.CapitalizationNone == this.capitalization && DisplayContext.LengthFull == this.nameLength && DisplayContext.Substitute == this.substituteHandling && locale.Equals(this.locale))) { this.locale = locale; this.dialectHandling = dialectHandling; this.capitalization = DisplayContext.CapitalizationNone; this.nameLength = DisplayContext.LengthFull; this.substituteHandling = DisplayContext.Substitute; this.cache = new LocaleDisplayNamesImpl(locale, dialectHandling); } } finally { syncLock.ExitWriteLock(); } } return(cache); } finally { syncLock.ExitUpgradeableReadLock(); } }
/// <summary> /// Convenience overload of <see cref="GetInstance(UCultureInfo, DialectHandling)"/> that /// returns names formatted for the provided <paramref name="locale"/>, /// using the provided <paramref name="dialectHandling"/>. /// </summary> /// <param name="locale">The display locale.</param> /// <param name="dialectHandling">How to select names for locales.</param> /// <returns>A <see cref="CultureDisplayNames"/> instance.</returns> /// <draft>ICU 60</draft> public static CultureDisplayNames GetInstance(CultureInfo locale, DialectHandling dialectHandling) { return(GetInstance(locale.ToUCultureInfo(), dialectHandling)); }
public LocaleDisplayNamesImpl(ULocale locale, params DisplayContext[] contexts) #pragma warning disable 612, 618 : base() #pragma warning restore 612, 618 { DialectHandling dialectHandling = DialectHandling.STANDARD_NAMES; DisplayContext capitalization = DisplayContext.CapitalizationNone; DisplayContext nameLength = DisplayContext.LengthFull; DisplayContext substituteHandling = DisplayContext.Substitute; foreach (DisplayContext contextItem in contexts) { switch (contextItem.Type()) { case DisplayContextType.DialectHandling: dialectHandling = (contextItem.Value() == DisplayContext.StandardNames.Value()) ? DialectHandling.STANDARD_NAMES : DialectHandling.DIALECT_NAMES; break; case DisplayContextType.Capitalization: capitalization = contextItem; break; case DisplayContextType.DisplayLength: nameLength = contextItem; break; case DisplayContextType.SubstituteHandling: substituteHandling = contextItem; break; default: break; } } this.dialectHandling = dialectHandling; this.capitalization = capitalization; this.nameLength = nameLength; this.substituteHandling = substituteHandling; this.langData = LangDataTables.impl.Get(locale, substituteHandling == DisplayContext.NoSubstitute); this.regionData = RegionDataTables.impl.Get(locale, substituteHandling == DisplayContext.NoSubstitute); this.locale = ULocale.ROOT.Equals(langData.GetLocale()) ? regionData.GetLocale() : langData.GetLocale(); // Note, by going through DataTable, this uses table lookup rather than straight lookup. // That should get us the same data, I think. This way we don't have to explicitly // load the bundle again. Using direct lookup didn't seem to make an appreciable // difference in performance. string sep = langData.Get("localeDisplayPattern", "separator"); if (sep == null || "separator".Equals(sep)) { sep = "{0}, {1}"; } StringBuilder sb = new StringBuilder(); this.separatorFormat = SimpleFormatterImpl.CompileToStringMinMaxArguments(sep, sb, 2, 2); string pattern = langData.Get("localeDisplayPattern", "pattern"); if (pattern == null || "pattern".Equals(pattern)) { pattern = "{0} ({1})"; } this.format = SimpleFormatterImpl.CompileToStringMinMaxArguments(pattern, sb, 2, 2); if (pattern.Contains("(")) { formatOpenParen = '('; formatCloseParen = ')'; formatReplaceOpenParen = '['; formatReplaceCloseParen = ']'; } else { formatOpenParen = '('; formatCloseParen = ')'; formatReplaceOpenParen = '['; formatReplaceCloseParen = ']'; } string keyTypePattern = langData.Get("localeDisplayPattern", "keyTypePattern"); if (keyTypePattern == null || "keyTypePattern".Equals(keyTypePattern)) { keyTypePattern = "{0}={1}"; } this.keyTypeFormat = SimpleFormatterImpl.CompileToStringMinMaxArguments( keyTypePattern, sb, 2, 2); // Get values from the contextTransforms data if we need them // Also check whether we will need a break iterator (depends on the data) bool needBrkIter = false; if (capitalization == DisplayContext.CapitalizationForUIListOrMenu || capitalization == DisplayContext.CapitalizationForStandalone) { capitalizationUsage = new bool[Enum.GetValues(typeof(CapitalizationContextUsage)).Length]; // initialized to all false ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.ICU_BASE_NAME, locale); CapitalizationContextSink sink = new CapitalizationContextSink(this); try { rb.GetAllItemsWithFallback("contextTransforms", sink); } catch (MissingManifestResourceException e) { // Silently ignore. Not every locale has contextTransforms. } needBrkIter = sink.hasCapitalizationUsage; } // Get a sentence break iterator if we will need it if (needBrkIter || capitalization == DisplayContext.CapitalizationForBeginningOfSentence) { capitalizationBrkIter = BreakIterator.GetSentenceInstance(locale); } this.currencyDisplayInfo = CurrencyData.Provider.GetInstance(locale, false); }
public LocaleDisplayNamesImpl(ULocale locale, DialectHandling dialectHandling) : this(locale, (dialectHandling == DialectHandling.STANDARD_NAMES) ? DisplayContext.StandardNames : DisplayContext.DialectNames, DisplayContext.CapitalizationNone) { }
public LocaleDisplayNames Get(ULocale locale, params DisplayContext[] contexts) { DialectHandling dialectHandlingIn = DialectHandling.StandardNames; DisplayContext capitalizationIn = DisplayContext.CapitalizationNone; DisplayContext nameLengthIn = DisplayContext.LengthFull; DisplayContext substituteHandling = DisplayContext.Substitute; foreach (DisplayContext contextItem in contexts) { switch (contextItem.Type()) { case DisplayContextType.DialectHandling: dialectHandlingIn = (contextItem.Value() == DisplayContext.StandardNames.Value()) ? DialectHandling.StandardNames : DialectHandling.DialectNames; break; case DisplayContextType.Capitalization: capitalizationIn = contextItem; break; case DisplayContextType.DisplayLength: nameLengthIn = contextItem; break; case DisplayContextType.SubstituteHandling: substituteHandling = contextItem; break; default: break; } } syncLock.EnterUpgradeableReadLock(); try { if (!(dialectHandlingIn == this.dialectHandling && capitalizationIn == this.capitalization && nameLengthIn == this.nameLength && substituteHandling == this.substituteHandling && locale.Equals(this.locale))) { syncLock.EnterWriteLock(); try { if (!(dialectHandlingIn == this.dialectHandling && capitalizationIn == this.capitalization && nameLengthIn == this.nameLength && substituteHandling == this.substituteHandling && locale.Equals(this.locale))) { this.locale = locale; this.dialectHandling = dialectHandlingIn; this.capitalization = capitalizationIn; this.nameLength = nameLengthIn; this.substituteHandling = substituteHandling; this.cache = new LocaleDisplayNamesImpl(locale, contexts); } } finally { syncLock.ExitWriteLock(); } } return(cache); } finally { syncLock.ExitUpgradeableReadLock(); } }
new public static LocaleDisplayNames GetInstance(ULocale locale, DialectHandling dialectHandling) { // ICU4N: Switched to using ReaderWriterLockSlim instead of lock (cache) return(cache.Get(locale, dialectHandling)); }