public BasicDurationFormat(ULocale locale) : base(locale) { this.pfs = null; pfs = IBM.ICU.Impl.Duration.BasicPeriodFormatterService.GetInstance(); formatter = pfs.NewDurationFormatterFactory() .SetLocale(locale.GetName()).GetFormatter(); pformatter = pfs.NewPeriodFormatterFactory() .SetDisplayPastFuture(false).SetLocale(locale.GetName()) .GetFormatter(); }
/// <summary> /// Create a <see cref="LocaleKey"/> with canonical primary and fallback IDs. /// </summary> public static LocaleKey CreateWithCanonical(ULocale locale, string canonicalFallbackID, int kind) { if (locale == null) { return(null); } string canonicalPrimaryID = locale.GetName(); return(new LocaleKey(canonicalPrimaryID, canonicalPrimaryID, canonicalFallbackID, kind)); }
/// <summary> /// Create a <see cref="LocaleKey"/> with canonical primary and fallback IDs. /// </summary> public static LocaleKey CreateWithCanonicalFallback(string primaryID, string canonicalFallbackID, int kind) { if (primaryID == null) { return(null); } string canonicalPrimaryID = ULocale.GetName(primaryID); return(new LocaleKey(primaryID, canonicalPrimaryID, canonicalFallbackID, kind)); }
/// <summary> /// Create a LocaleKey with canonical primary and fallback IDs. /// </summary> /// public static ICULocaleService.LocaleKey CreateWithCanonical(ULocale locale, String canonicalFallbackID, int kind_0) { if (locale == null) { return(null); } String canonicalPrimaryID = locale.GetName(); return(new ICULocaleService.LocaleKey(canonicalPrimaryID, canonicalPrimaryID, canonicalFallbackID, kind_0)); }
public static CollationTailoring LoadTailoring(ULocale locale, out ULocale outValidLocale) { // Java porting note: ICU4J getWithFallback/getStringWithFallback currently does not // work well when alias table is involved in a resource path, unless full path is specified. // For now, collation resources does not contain such data, so the code below should work fine. CollationTailoring root = CollationRoot.Root; string localeName = locale.GetName(); if (localeName.Length == 0 || localeName.Equals("root")) { outValidLocale = ULocale.ROOT; return(root); } UResourceBundle bundle = null; try { bundle = ICUResourceBundle.GetBundleInstance( ICUData.ICU_COLLATION_BASE_NAME, locale, // ICU4N specific - need to pass in this assembly // name for the resources to be resolved here. CollationData.ICU_DATA_CLASS_LOADER, ICUResourceBundle.OpenType.LOCALE_ROOT); } catch (MissingManifestResourceException e) { outValidLocale = ULocale.ROOT; return(root); } ULocale validLocale = bundle.GetULocale(); // Normalize the root locale. See // http://bugs.icu-project.org/trac/ticket/10715 string validLocaleName = validLocale.GetName(); if (validLocaleName.Length == 0 || validLocaleName.Equals("root")) { validLocale = ULocale.ROOT; } outValidLocale = validLocale; // There are zero or more tailorings in the collations table. UResourceBundle collations; try { collations = bundle.Get("collations"); if (collations == null) { return(root); } } catch (MissingManifestResourceException ignored) { return(root); } // Fetch the collation type from the locale ID and the default type from the data. string type = locale.GetKeywordValue("collation"); string defaultType = "standard"; string defT = ((ICUResourceBundle)collations).FindStringWithFallback("default"); if (defT != null) { defaultType = defT; } if (type == null || type.Equals("default")) { type = defaultType; } else { type = ASCII.ToLower(type); } // Load the collations/type tailoring, with type fallback. // Java porting note: typeFallback is used for setting U_USING_DEFAULT_WARNING in // ICU4C, but not used by ICU4J // boolean typeFallback = false; UResourceBundle data = FindWithFallback(collations, type); if (data == null && type.Length > 6 && type.StartsWith("search", StringComparison.Ordinal)) { // fall back from something like "searchjl" to "search" // typeFallback = true; type = "search"; data = FindWithFallback(collations, type); } if (data == null && !type.Equals(defaultType)) { // fall back to the default type // typeFallback = true; type = defaultType; data = FindWithFallback(collations, type); } if (data == null && !type.Equals("standard")) { // fall back to the "standard" type // typeFallback = true; type = "standard"; data = FindWithFallback(collations, type); } if (data == null) { return(root); } // Is this the same as the root collator? If so, then use that instead. ULocale actualLocale = data.GetULocale(); // http://bugs.icu-project.org/trac/ticket/10715 ICUResourceBundle(root).getULocale() != ULocale.ROOT // Therefore not just if (actualLocale.equals(ULocale.ROOT) && type.equals("standard")) { string actualLocaleName = actualLocale.GetName(); if (actualLocaleName.Length == 0 || actualLocaleName.Equals("root")) { actualLocale = ULocale.ROOT; if (type.Equals("standard")) { return(root); } } CollationTailoring t = new CollationTailoring(root.Settings); t.ActualLocale = actualLocale; // deserialize UResourceBundle binary = data.Get("%%CollationBin"); ByteBuffer inBytes = binary.GetBinary(); try { CollationDataReader.Read(root, inBytes, t); } catch (IOException e) { throw new ICUUncheckedIOException("Failed to load collation tailoring data for locale:" + actualLocale + " type:" + type, e); } // Try to fetch the optional rules string. try { t.SetRulesResource(data.Get("Sequence")); } catch (MissingManifestResourceException ignored) { } // Set the collation types on the informational locales, // except when they match the default types (for brevity and backwards compatibility). // For the valid locale, suppress the default type. if (!type.Equals(defaultType)) { outValidLocale = validLocale.SetKeywordValue("collation", type); } // For the actual locale, suppress the default type *according to the actual locale*. // For example, zh has default=pinyin and contains all of the Chinese tailorings. // zh_Hant has default=stroke but has no other data. // For the valid locale "zh_Hant" we need to suppress stroke. // For the actual locale "zh" we need to suppress pinyin instead. if (!actualLocale.Equals(validLocale)) { // Opening a bundle for the actual locale should always succeed. UResourceBundle actualBundle = UResourceBundle.GetBundleInstance( ICUData.ICU_COLLATION_BASE_NAME, actualLocale); defT = ((ICUResourceBundle)actualBundle).FindStringWithFallback("collations/default"); if (defT != null) { defaultType = defT; } } if (!type.Equals(defaultType)) { t.ActualLocale = t.ActualLocale.SetKeywordValue("collation", type); } // if (typeFallback) { // ICU4C implementation sets U_USING_DEFAULT_WARNING here // } return(t); }
// ------------------------------------------------------------------------- // Static class methods. // ------------------------------------------------------------------------- /// <summary> /// Provides access to the predefined <c>PluralRules</c> for a given /// locale. /// </summary> /// /// <param name="locale">The locale for which a <c>PluralRules</c> object isreturned.</param> /// <returns>The predefined <c>PluralRules</c> object for this locale. /// If there's no predefined rules for this locale, the rules for the /// closest parent in the locale hierarchy that has one will be /// returned. The final fallback always returns the default rules.</returns> /// @draft ICU 3.8 /// @provisional This API might change or be removed in a future release. public static PluralRules ForLocale(ULocale locale) { PluralRules result = null; while (null == (result = (PluralRules)ILOG.J2CsMapping.Collections.Collections.Get(ruleMap, locale.GetName()))) { locale = locale.GetFallback(); if (locale == null) { return(DEFAULT); } } return(result); }
internal override String GetDisplayName(ULocale objectLocale, ULocale displayLocale) { String id = objectLocale.GetName(); return(service.GetDisplayName(id, displayLocale)); }
public void TestRegisterFactory() { ULocale fu_FU = new ULocale("fu_FU"); ULocale fu_FU_FOO = new ULocale("fu_FU_FOO"); IDictionary <object, object> fuFUNames = new Dictionary <object, object> { { fu_FU, "ze leetle bunny Fu-Fu" }, { fu_FU_FOO, "zee leetel bunny Foo-Foo" }, { ULocale.US, "little bunny Foo Foo" } }; Collator frcol = Collator.GetInstance(ULocale.FRANCE); /* Collator uscol = */ Collator.GetInstance(ULocale.US); Collator gecol = Collator.GetInstance(ULocale.GERMANY); Collator jpcol = Collator.GetInstance(ULocale.JAPAN); Collator fucol = Collator.GetInstance(fu_FU); CollatorInfo[] info = { new CollatorInfo(ULocale.US, frcol, null), new CollatorInfo(ULocale.FRANCE, gecol, null), new CollatorInfo(fu_FU, jpcol, fuFUNames), }; TestFactory factory = null; try { factory = new TestFactory(info); } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } // coverage { TestFactoryWrapper wrapper = new TestFactoryWrapper(factory); // in java, gc lets us easily multiply reference! Object key = Collator.RegisterFactory(wrapper); String name = null; try { name = Collator.GetDisplayName(fu_FU, fu_FU_FOO); } catch (MissingManifestResourceException ex) { Warnln("Could not load locale data."); } Logln("*** default name: " + name); Collator.Unregister(key); ULocale bar_BAR = new ULocale("bar_BAR"); Collator col = Collator.GetInstance(bar_BAR); ULocale valid = col.GetLocale(ULocale.VALID_LOCALE); String validName = valid.GetName(); if (validName.Length != 0 && !validName.Equals("root")) { Errln("Collation from bar_BAR is really \"" + validName + "\" but should be root"); } } int n1 = checkAvailable("before registerFactory"); { Object key = Collator.RegisterFactory(factory); int n2 = checkAvailable("after registerFactory"); Collator ncol = Collator.GetInstance(ULocale.US); if (!frcol.Equals(ncol)) { Errln("frcoll for en_US failed"); } ncol = Collator.GetInstance(fu_FU_FOO); if (!jpcol.Equals(ncol)) { Errln("jpcol for fu_FU_FOO failed, got: " + ncol); } ULocale[] locales = Collator.GetAvailableULocales(); bool found = false; for (int i = 0; i < locales.Length; ++i) { if (locales[i].Equals(fu_FU)) { found = true; break; } } if (!found) { Errln("new locale fu_FU not reported as supported locale"); } String name = Collator.GetDisplayName(fu_FU); if (!"little bunny Foo Foo".Equals(name)) { Errln("found " + name + " for fu_FU"); } name = Collator.GetDisplayName(fu_FU, fu_FU_FOO); if (!"zee leetel bunny Foo-Foo".Equals(name)) { Errln("found " + name + " for fu_FU in fu_FU_FOO"); } if (!Collator.Unregister(key)) { Errln("failed to unregister factory"); } int n3 = checkAvailable("after unregister"); assertTrue("register increases count", n2 > n1); assertTrue("unregister restores count", n3 == n1); ncol = Collator.GetInstance(fu_FU); if (!fucol.Equals(ncol)) { Errln("collator after unregister does not match original fu_FU"); } } }
public static CultureInfo Fallback(ULocale locale) { return(Fallback(locale.GetName())); }
public override string LocaleDisplayName(ULocale locale) { return(locale.GetName()); }