示例#1
0
        /// <summary>
        /// Returns the functionally equivalent locale.
        /// </summary>
#pragma warning disable 672
        public override ULocale GetFunctionalEquivalent(ULocale locale, bool[] isAvailable)
#pragma warning restore 672
        {
            if (isAvailable != null && isAvailable.Length > 0)
            {
                string localeId = ULocale.Canonicalize(locale.GetBaseName());
                IDictionary <string, string> idMap = GetLocaleIdToRulesIdMap(PluralType.Cardinal);
                isAvailable[0] = idMap.ContainsKey(localeId);
            }

            string rulesId = GetRulesIdForLocale(locale, PluralType.Cardinal);

            if (rulesId == null || rulesId.Trim().Length == 0)
            {
                return(ULocale.ROOT); // ultimate fallback
            }

            ULocale result;

            GetRulesIdToEquivalentULocaleMap().TryGetValue(rulesId, out result);
            if (result == null)
            {
                return(ULocale.ROOT); // ultimate fallback
            }

            return(result);
        }
示例#2
0
 public SimpleLocaleKeyFactory(Object obj_0, ULocale locale, int kind_1,
                               bool visible_2, String name_3) : base(visible_2, name_3)
 {
     this.obj  = obj_0;
     this.id   = locale.GetBaseName();
     this.kind = kind_1;
 }
示例#3
0
 public SimpleLocaleKeyFactory(object obj, ULocale locale, int kind, bool visible, string name)
     : base(visible, name)
 {
     this.obj  = obj;
     this.id   = locale.GetBaseName();
     this.kind = kind;
 }
示例#4
0
        /// <summary>
        /// Utility to fetch locale display data from resource bundle tables.  Convenience
        /// wrapper for <see cref="GetTableString(ICUResourceBundle, string, string, string, string)"/>.
        /// </summary>
        public static string GetTableString(string path, ULocale locale, string tableName,
                                            string itemName, string defaultValue)
        {
            ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.
                                       GetBundleInstance(path, locale.GetBaseName());

            return(GetTableString(bundle, tableName, null, itemName, defaultValue));
        }
示例#5
0
 /// <summary>
 /// Creates a resource bundle for the given base name and locale in the
 /// default ICU package.
 /// </summary>
 ///
 /// <param name="bundleName">the base name of the bundle to retrieve, e.g."LocaleElements".</param>
 /// <param name="locale">the locale of the bundle to retrieve, or null to use thedefault locale</param>
 /// <returns>a ResourceBundle with the given base name for the given locale,
 /// or null on failure</returns>
 public static ResourceBundle GetResourceBundle(String bundleName,
                                                ULocale locale)
 {
     if (locale == null)
     {
         locale = IBM.ICU.Util.ULocale.GetDefault();
     }
     return(GetResourceBundle(ICU_PACKAGE, bundleName, locale.GetBaseName()));
 }
示例#6
0
 /// <summary>
 /// Creates a LocaleElements resource bundle for the given locale in the
 /// default ICU package.
 /// </summary>
 ///
 /// <param name="locale">the locale of the bundle to retrieve, or null to use thedefault locale</param>
 /// <returns>a ResourceBundle for the LocaleElements of the given locale, or
 /// null on failure</returns>
 public static ResourceBundle GetLocaleElements(ULocale locale)
 {
     if (locale == null)
     {
         locale = IBM.ICU.Util.ULocale.GetDefault();
     }
     return(GetResourceBundle(ICU_PACKAGE, LOCALE_ELEMENTS,
                              locale.GetBaseName()));
 }
示例#7
0
 /// <summary>
 /// Get a resource bundle from the resource bundle path. Unlike
 /// getResourceBundle, this returns an 'unparented' bundle that exactly
 /// matches the bundle name and locale name.
 /// </summary>
 ///
 public static ResourceManager LoadResourceBundle(String bundleName,
                                                  ULocale locale)
 {
     if (locale == null)
     {
         locale = IBM.ICU.Util.ULocale.GetDefault();
     }
     return(LoadResourceBundle(bundleName, locale.GetBaseName()));
 }
示例#8
0
 /**
  * {@icu} Creates a UResourceBundle for the locale specified, from which users can extract
  * resources by using their corresponding keys.
  * @param locale  specifies the locale for which we want to open the resource.
  *                If null the bundle for default locale is opened.
  * @return a resource bundle for the given locale
  * @stable ICU 3.0
  */
 public static UResourceBundle GetBundleInstance(ULocale locale)
 {
     if (locale == null)
     {
         locale = ULocale.GetDefault();
     }
     return(GetBundleInstance(ICUData.ICU_BASE_NAME, locale.GetBaseName(),
                              ICUResourceBundle.ICU_DATA_CLASS_LOADER, false));
 }
示例#9
0
        /**
         * {@icu} Creates a UResourceBundle for the specified locale and specified base name,
         * from which users can extract resources by using their corresponding keys.
         * @param baseName string containing the name of the data package.
         *                    If null the default ICU package name is used.
         * @param locale  specifies the locale for which we want to open the resource.
         *                If null the bundle for default locale is opened.
         * @param loader  the loader to use
         * @return a resource bundle for the given base name and locale
         * @stable ICU 3.8
         */
        public static UResourceBundle GetBundleInstance(string baseName, CultureInfo locale,
                                                        Assembly loader)
        {
            if (baseName == null)
            {
                baseName = ICUData.ICU_BASE_NAME;
            }
            ULocale uloc = locale == null?ULocale.GetDefault() : ULocale.ForLocale(locale);

            return(GetBundleInstance(baseName, uloc.GetBaseName(), loader, false));
        }
示例#10
0
 /**
  * {@icu} Creates a UResourceBundle, from which users can extract resources by using
  * their corresponding keys.<br><br>
  * Note: Please use this API for loading non-ICU resources. Java security does not
  * allow loading of resources across jar files. You must provide your class loader
  * to load the resources
  * @param baseName string containing the name of the data package.
  *                    If null the default ICU package name is used.
  * @param locale  specifies the locale for which we want to open the resource.
  *                If null the bundle for default locale is opened.
  * @param loader  the loader to use
  * @return a resource bundle for the given base name and locale
  * @stable ICU 3.8
  */
 public static UResourceBundle GetBundleInstance(string baseName, ULocale locale,
                                                 Assembly loader)
 {
     if (baseName == null)
     {
         baseName = ICUData.ICU_BASE_NAME;
     }
     if (locale == null)
     {
         locale = ULocale.GetDefault();
     }
     return(GetBundleInstance(baseName, locale.GetBaseName(), loader, false));
 }
示例#11
0
        /**
         * {@icu} Creates a UResourceBundle for the specified locale and specified base name,
         * from which users can extract resources by using their corresponding keys.
         * @param baseName string containing the name of the data package.
         *                    If null the default ICU package name is used.
         * @param locale  specifies the locale for which we want to open the resource.
         *                If null the bundle for default locale is opened.
         * @return a resource bundle for the given base name and locale
         * @stable ICU 3.0
         */

        public static UResourceBundle GetBundleInstance(string baseName, CultureInfo locale)
        {
            if (baseName == null)
            {
                baseName = ICUData.ICU_BASE_NAME;
            }
            ULocale uloc = locale == null?ULocale.GetDefault() : ULocale.ForLocale(locale);

            //return GetBundleInstance(baseName, uloc.GetBaseName(),
            //                         ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
            return(GetBundleInstance(baseName, uloc.GetBaseName(),
                                     GetAssembly(baseName), false));
        }
示例#12
0
 /// <summary>
 /// Return the name of the collator for the objectLocale, localized for
 /// the displayLocale. If objectLocale is not visible or not defined by
 /// the factory, return null.
 /// </summary>
 ///
 /// <param name="objectLocale">the locale identifying the collator</param>
 /// <param name="displayLocale">the locale for which the display name of the collatorshould be localized</param>
 /// <returns>the display name</returns>
 /// @stable ICU 3.2
 public String GetDisplayName(ULocale objectLocale, ULocale displayLocale)
 {
     if (Visible())
     {
         ILOG.J2CsMapping.Collections.ISet supported = GetSupportedLocaleIDs();
         String name = objectLocale.GetBaseName();
         if (ILOG.J2CsMapping.Collections.Collections.Contains(name, supported))
         {
             return(objectLocale.GetDisplayName(displayLocale));
         }
     }
     return(null);
 }
示例#13
0
 /**
  * {@icu} Creates a UResourceBundle, from which users can extract resources by using
  * their corresponding keys.
  * @param baseName string containing the name of the data package.
  *                    If null the default ICU package name is used.
  * @param locale  specifies the locale for which we want to open the resource.
  *                If null the bundle for default locale is opened.
  * @return a resource bundle for the given base name and locale
  * @stable ICU 3.0
  */
 public static UResourceBundle GetBundleInstance(string baseName, ULocale locale)
 {
     if (baseName == null)
     {
         baseName = ICUData.ICU_BASE_NAME;
     }
     if (locale == null)
     {
         locale = ULocale.GetDefault();
     }
     //return GetBundleInstance(baseName, locale.GetBaseName(),
     //                         ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
     return(GetBundleInstance(baseName, locale.GetBaseName(),
                              GetAssembly(baseName), false));
 }
示例#14
0
        /// <summary>
        /// Return the name of the current fallback locale. If it has changed since
        /// this was last accessed, the service cache is cleared.
        /// </summary>
        ///
        public String ValidateFallbackLocale()
        {
            ULocale loc = IBM.ICU.Util.ULocale.GetDefault();

            if (loc != fallbackLocale)
            {
                lock (this) {
                    if (loc != fallbackLocale)
                    {
                        fallbackLocale     = loc;
                        fallbackLocaleName = loc.GetBaseName();
                        ClearServiceCache();
                    }
                }
            }
            return(fallbackLocaleName);
        }
示例#15
0
        /// <summary>
        /// Gets the rulesId from the locale,with locale fallback. If there is no
        /// rulesId, return null. The rulesId might be the empty string if the rule
        /// is the default rule.
        /// </summary>
        public virtual string GetRulesIdForLocale(ULocale locale, PluralType type)
        {
            IDictionary <string, string> idMap = GetLocaleIdToRulesIdMap(type);
            string localeId = ULocale.Canonicalize(locale.GetBaseName());
            string rulesId  = null;

            while (!idMap.TryGetValue(localeId, out rulesId) || null == rulesId)
            {
                int ix = localeId.LastIndexOf('_');
                if (ix == -1)
                {
                    break;
                }
                localeId = localeId.Substring(0, ix); // ICU4N: Checked 2nd substring arg
            }
            return(rulesId);
        }
示例#16
0
        /// <summary>
        /// Returns the default numbering system for the specified <see cref="ULocale"/>.
        /// </summary>
        /// <stable>ICU 4.2</stable>
        public static NumberingSystem GetInstance(ULocale locale)
        {
            // Check for @numbers
            bool   nsResolved     = true;
            string numbersKeyword = locale.GetKeywordValue("numbers");

            if (numbersKeyword != null)
            {
                foreach (string keyword in OTHER_NS_KEYWORDS)
                {
                    if (numbersKeyword.Equals(keyword))
                    {
                        nsResolved = false;
                        break;
                    }
                }
            }
            else
            {
                numbersKeyword = "default";
                nsResolved     = false;
            }

            if (nsResolved)
            {
                NumberingSystem ns = GetInstanceByName(numbersKeyword);
                if (ns != null)
                {
                    return(ns);
                }
                // If the @numbers keyword points to a bogus numbering system name,
                // we return the default for the locale.
                numbersKeyword = "default";
            }

            // Attempt to get the numbering system from the cache
            string baseName = locale.GetBaseName();
            // TODO: Caching by locale+numbersKeyword could yield a large cache.
            // Try to load for each locale the mappings from OTHER_NS_KEYWORDS and default
            // to real numbering system names; can we get those from supplemental data?
            // Then look up those mappings for the locale and resolve the keyword.
            string           key = baseName + "@numbers=" + numbersKeyword;
            LocaleLookupData localeLookupData = new LocaleLookupData(locale, numbersKeyword);

            return(cachedLocaleData.GetOrCreate(key, (k) => LookupInstanceByLocale(localeLookupData)));
        }
示例#17
0
#pragma warning restore 612, 618

#pragma warning disable 1591 // No doc comments available
#pragma warning disable 612, 618
        public virtual PluralRanges GetPluralRanges(ULocale locale)
#pragma warning restore 612, 618
        {
            // TODO markdavis Fix the bad fallback, here and elsewhere in this file.
            string localeId = ULocale.Canonicalize(locale.GetBaseName());

#pragma warning disable 612, 618
            PluralRanges result;
#pragma warning restore 612, 618
            while (!localeIdToPluralRanges.TryGetValue(localeId, out result) || null == result)
            {
                int ix = localeId.LastIndexOf('_');
                if (ix == -1)
                {
                    result = UnknownRange;
                    break;
                }
                localeId = localeId.Substring(0, ix); // ICU4N: Checked 2nd arg
            }
            return(result);
        }
示例#18
0
 public ICUDataTable(string path, ULocale locale, bool nullIfNotFound)
     : base(nullIfNotFound)
 {
     this.bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(
         path, locale.GetBaseName());
 }
示例#19
0
        private static BreakIterator CreateBreakInstance(ULocale locale, int kind)
        {
            RuleBasedBreakIterator iter = null;
            ICUResourceBundle      rb   = ICUResourceBundle.
                                          GetBundleInstance(ICUData.ICU_BRKITR_BASE_NAME, locale,
                                                            ICUResourceBundle.OpenType.LOCALE_ROOT);

            //
            //  Get the binary rules.
            //
            ByteBuffer bytes      = null;
            string     typeKeyExt = null;

            if (kind == BreakIterator.KIND_LINE)
            {
                string lbKeyValue = locale.GetKeywordValue("lb");
                if (lbKeyValue != null && (lbKeyValue.Equals("strict") || lbKeyValue.Equals("normal") || lbKeyValue.Equals("loose")))
                {
                    typeKeyExt = "_" + lbKeyValue;
                }
            }

            try
            {
                string typeKey       = (typeKeyExt == null) ? KIND_NAMES[kind] : KIND_NAMES[kind] + typeKeyExt;
                string brkfname      = rb.GetStringWithFallback("boundaries/" + typeKey);
                string rulesFileName = ICUData.ICU_BRKITR_NAME + '/' + brkfname;
                bytes = ICUBinary.GetData(rulesFileName);
            }
            catch (Exception e)
            {
                throw new MissingManifestResourceException(e.ToString(), e /*, "", ""*/);
            }

            //
            // Create a normal RuleBasedBreakIterator.
            //
            try
            {
#pragma warning disable 612, 618
                iter = RuleBasedBreakIterator.GetInstanceFromCompiledRules(bytes);
#pragma warning restore 612, 618
            }
            catch (IOException e)
            {
                // Shouldn't be possible to get here.
                // If it happens, the compiled rules are probably corrupted in some way.
                Assert.Fail(e);
            }
            // TODO: Determine valid and actual locale correctly.
            ULocale uloc = ULocale.ForLocale(rb.GetLocale());
            iter.SetLocale(uloc, uloc);
            iter.BreakType = kind;

            // filtered break
            if (kind == BreakIterator.KIND_SENTENCE)
            {
                string ssKeyword = locale.GetKeywordValue("ss");
                if (ssKeyword != null && ssKeyword.Equals("standard"))
                {
                    ULocale @base = new ULocale(locale.GetBaseName());
                    return(FilteredBreakIteratorBuilder.GetInstance(@base).WrapIteratorWithFilter(iter));
                }
            }

            return(iter);
        }
示例#20
0
        // TODO: implement use of capitalization
        private string LocaleDisplayNameInternal(ULocale locale)
        {
            // lang
            // lang (script, country, variant, keyword=value, ...)
            // script, country, variant, keyword=value, ...

            string resultName = null;

            string lang = locale.GetLanguage();

            // Empty basename indicates root locale (keywords are ignored for this).
            // Our data uses 'root' to access display names for the root locale in the
            // "Languages" table.
            if (locale.GetBaseName().Length == 0)
            {
                lang = "root";
            }
            string script  = locale.GetScript();
            string country = locale.GetCountry();
            string variant = locale.GetVariant();

            bool hasScript  = script.Length > 0;
            bool hasCountry = country.Length > 0;
            bool hasVariant = variant.Length > 0;

            // always have a value for lang
            if (dialectHandling == DialectHandling.DIALECT_NAMES)
            {
                do
                { // loop construct is so we can break early out of search
                    if (hasScript && hasCountry)
                    {
                        string langScriptCountry = lang + '_' + script + '_' + country;
                        string result            = LocaleIdName(langScriptCountry);
                        if (result != null && !result.Equals(langScriptCountry))
                        {
                            resultName = result;
                            hasScript  = false;
                            hasCountry = false;
                            break;
                        }
                    }
                    if (hasScript)
                    {
                        string langScript = lang + '_' + script;
                        string result     = LocaleIdName(langScript);
                        if (result != null && !result.Equals(langScript))
                        {
                            resultName = result;
                            hasScript  = false;
                            break;
                        }
                    }
                    if (hasCountry)
                    {
                        string langCountry = lang + '_' + country;
                        string result      = LocaleIdName(langCountry);
                        if (result != null && !result.Equals(langCountry))
                        {
                            resultName = result;
                            hasCountry = false;
                            break;
                        }
                    }
                } while (false);
            }

            if (resultName == null)
            {
                string result = LocaleIdName(lang);
                if (result == null)
                {
                    return(null);
                }
                resultName = result
                             .Replace(formatOpenParen, formatReplaceOpenParen)
                             .Replace(formatCloseParen, formatReplaceCloseParen);
            }

            StringBuilder buf = new StringBuilder();

            if (hasScript)
            {
                // first element, don't need appendWithSep
                string result = ScriptDisplayNameInContext(script, true);
                if (result == null)
                {
                    return(null);
                }
                buf.Append(result
                           .Replace(formatOpenParen, formatReplaceOpenParen)
                           .Replace(formatCloseParen, formatReplaceCloseParen));
            }
            if (hasCountry)
            {
                string result = RegionDisplayName(country, true);
                if (result == null)
                {
                    return(null);
                }
                AppendWithSep(result
                              .Replace(formatOpenParen, formatReplaceOpenParen)
                              .Replace(formatCloseParen, formatReplaceCloseParen), buf);
            }
            if (hasVariant)
            {
                string result = VariantDisplayName(variant, true);
                if (result == null)
                {
                    return(null);
                }
                AppendWithSep(result
                              .Replace(formatOpenParen, formatReplaceOpenParen)
                              .Replace(formatCloseParen, formatReplaceCloseParen), buf);
            }

            using (IEnumerator <string> keys = locale.GetKeywords())
            {
                if (keys != null)
                {
                    while (keys.MoveNext())
                    {
                        string key            = keys.Current;
                        string value          = locale.GetKeywordValue(key);
                        string keyDisplayName = KeyDisplayName(key, true);
                        if (keyDisplayName == null)
                        {
                            return(null);
                        }
                        keyDisplayName = keyDisplayName
                                         .Replace(formatOpenParen, formatReplaceOpenParen)
                                         .Replace(formatCloseParen, formatReplaceCloseParen);
                        string valueDisplayName = KeyValueDisplayName(key, value, true);
                        if (valueDisplayName == null)
                        {
                            return(null);
                        }
                        valueDisplayName = valueDisplayName
                                           .Replace(formatOpenParen, formatReplaceOpenParen)
                                           .Replace(formatCloseParen, formatReplaceCloseParen);
                        if (!valueDisplayName.Equals(value))
                        {
                            AppendWithSep(valueDisplayName, buf);
                        }
                        else if (!key.Equals(keyDisplayName))
                        {
                            string keyValue = SimpleFormatterImpl.FormatCompiledPattern(
                                keyTypeFormat, keyDisplayName, valueDisplayName);
                            AppendWithSep(keyValue, buf);
                        }
                        else
                        {
                            AppendWithSep(keyDisplayName, buf)
                            .Append("=")
                            .Append(valueDisplayName);
                        }
                    }
                }
            }
            string resultRemainder = null;

            if (buf.Length > 0)
            {
                resultRemainder = buf.ToString();
            }

            if (resultRemainder != null)
            {
                resultName = SimpleFormatterImpl.FormatCompiledPattern(
                    format, resultName, resultRemainder);
            }

            return(AdjustForUsageAndContext(CapitalizationContextUsage.LANGUAGE, resultName));
        }