// Ported from C++ Collator::makeInstance().
        internal static Collator MakeInstance(UCultureInfo desiredLocale)
        {
            CollationTailoring t =
                CollationLoader.LoadTailoring(desiredLocale, out UCultureInfo validLocale);

            return(new RuleBasedCollator(t, validLocale));
        }
Beispiel #2
0
        public void TestT5615()
        {
            UCultureInfo[] ulocales = BreakIterator.GetUCultures(UCultureTypes.AllCultures);
            int            type     = 0;
            UCultureInfo   loc      = null;

            try
            {
                for (int i = 0; i < ulocales.Length; i++)
                {
                    loc = ulocales[i];
                    for (type = 0; type < 5 /* 5 = BreakIterator.KIND_COUNT */; ++type)
                    {
                        BreakIterator brk = BreakIterator.GetBreakInstance(loc, type);
                        if (brk == null)
                        {
                            Errln("ERR: Failed to create an instance type: " + type + " / locale: " + loc);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Errln("ERR: Failed to create an instance type: " + type + " / locale: " + loc + " / exception: " + e.ToString());
            }
        }
Beispiel #3
0
        public static BreakIterator GetTitleBreakIterator(
            UCultureInfo locale, int options, BreakIterator iter)
        {
            options &= TITLECASE_ITERATOR_MASK;
            if (options != 0 && iter != null)
            {
                throw new ArgumentException(
                          "titlecasing iterator option together with an explicit iterator");
            }
            if (iter == null)
            {
                switch (options)
                {
                case 0:
                    iter = BreakIterator.GetWordInstance(locale);
                    break;

                case TitleCaseWholeString:
                    iter = new WholeStringBreakIterator();
                    break;

                case TitleCaseSentences:
                    iter = BreakIterator.GetSentenceInstance(locale);
                    break;

                default:
                    throw new ArgumentException("unknown titlecasing iterator option");
                }
            }
            return(iter);
        }
Beispiel #4
0
        public void TestCollation()
        {
            using (new ThreadCultureChange(_DEFAULT_LOCALE, _DEFAULT_LOCALE))
            {
                for (int i = 0; i < _LOCALE_NUMBER; i++)
                {
                    UCultureInfo oldLoc = _LOCALES[i][0];
                    UCultureInfo newLoc = _LOCALES[i][1];
                    if (!availableMap.TryGetValue(_LOCALES[i][1], out object value) || value == null)
                    {
                        Logln(_LOCALES[i][1] + " is not available. Skipping!");
                        continue;
                    }
                    Collator c1 = Collator.GetInstance(oldLoc);
                    Collator c2 = Collator.GetInstance(newLoc);

                    if (!c1.Equals(c2))
                    {
                        Errln("CollationTest: c1!=c2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
                    }

                    Logln("Collation old:" + oldLoc + "   new:" + newLoc);
                }
            }
        }
        public void TestIllformedLocale()
        {
            UCultureInfo        french   = new UCultureInfo("fr");
            Collator            collator = Collator.GetInstance(french);
            CultureDisplayNames names    = CultureDisplayNames.GetInstance(french,
                                                                           new DisplayContextOptions {
                Capitalization = Capitalization.UIListOrMenu
            });

            foreach (String malformed in new string[] { "en-a", "$", "ü--a", "en--US" })
            {
                try
                {
                    ISet <UCultureInfo> supported = new HashSet <UCultureInfo> {
                        new UCultureInfo(malformed)
                    };                                                                                        //Collections.singleton(new UCultureInfo(malformed));
                    names.GetUiList(supported, false, collator);
                    assertNull("Failed to detect bogus locale «" + malformed + "»", supported);
                }
                catch (IllformedLocaleException e)
                {
                    Logln("Successfully detected ill-formed locale «" + malformed + "»:" + e.ToString());
                }
            }
        }
        internal override Collator GetInstance(UCultureInfo locale)
        {
            // use service cache, it's faster than instantiation
            //          if (service.isDefault()) {
            //              return new RuleBasedCollator(locale);
            //          }
            //try
            //{
            Collator coll = (Collator)service.Get(locale, out _);

            if (coll == null)
            {
                ////CLOVER:OFF
                //Can't really change coll after it's been initialized
                throw new MissingManifestResourceException("Could not locate Collator data");
                ////CLOVER:ON
            }
            return((Collator)coll.Clone());
            //}
            //catch (CloneNotSupportedException e)
            //{
            //    ////CLOVER:OFF
            //    throw new ICUCloneNotSupportedException(e);
            //    ////CLOVER:ON
            //}
        }
Beispiel #7
0
        /**
         * Convenience override of getDisplayNames(UCultureInfo, Comparer, string) that
         * uses the default collator for the locale as the comparator to
         * sort the display names.
         */
        public IDictionary <string, string> GetDisplayNames(ICUService service, UCultureInfo locale, string matchID)
        {
            //Collator col = Collator.getInstance(locale.toLocale());
            CompareInfo col = CompareInfo.GetCompareInfo(locale.ToCultureInfo().Name);

            return(service.GetDisplayNames(locale, col, matchID));
        }
Beispiel #8
0
        /// <summary>
        /// Returns the functionally equivalent locale.
        /// </summary>
#pragma warning disable 672
        public override UCultureInfo GetFunctionalEquivalent(UCultureInfo locale, bool[] isAvailable)
#pragma warning restore 672
        {
            if (isAvailable != null && isAvailable.Length > 0)
            {
                string localeId = UCultureInfo.Canonicalize(locale.Name);
                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(UCultureInfo.InvariantCulture); // ultimate fallback
            }

            UCultureInfo result;

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

            return(result);
        }
Beispiel #9
0
 internal TBItem(int typ, UCultureInfo loc, String txt, int[] eOffs)
 {
     type          = typ;
     locale        = loc;
     text          = txt;
     expectOffsets = eOffs;
 }
Beispiel #10
0
 public SimpleLocaleKeyFactory(object obj, UCultureInfo locale, int kind, bool visible, string name)
     : base(visible, name)
 {
     this.obj  = obj;
     this.id   = locale.Name;
     this.kind = kind;
 }
Beispiel #11
0
        public virtual CurrencyDisplayInfo GetInstance(UCultureInfo culture, bool withFallback)
        {
            // Make sure the locale is non-null (this can happen during deserialization):
            if (culture == null)
            {
                culture = UCultureInfo.InvariantCulture;
            }
            ICUCurrencyDisplayInfo instance = currencyDisplayInfoCache;

            if (instance == null || !culture.Equals(instance.culture) || instance.fallback != withFallback)
            {
                ICUResourceBundle rb;
                if (withFallback)
                {
                    rb = ICUResourceBundle.GetBundleInstance(ICUData.IcuCurrencyBaseName, culture, ICUResourceBundle.IcuDataAssembly, OpenType.LocaleDefaultRoot);
                }
                else
                {
                    try
                    {
                        rb = ICUResourceBundle.GetBundleInstance(ICUData.IcuCurrencyBaseName, culture, ICUResourceBundle.IcuDataAssembly, OpenType.LocaleOnly);
                    }
                    catch (MissingManifestResourceException)
                    {
                        return(null);
                    }
                }
                instance = new ICUCurrencyDisplayInfo(culture, rb, withFallback);
                currencyDisplayInfoCache = instance;
            }
            return(instance);
        }
        internal override NumberFormat CreateInstance(UCultureInfo desiredLocale, NumberFormatStyle choice)
        {
            // use service cache
            //          if (service.isDefault()) {
            //              return NumberFormat.createInstance(desiredLocale, choice);
            //          }

            NumberFormat fmt = (NumberFormat)service.Get(desiredLocale, (int)choice,
                                                         out UCultureInfo actualLoc);

            if (fmt == null)
            {
                throw new MissingManifestResourceException("Unable to construct NumberFormat");
            }
            fmt = (NumberFormat)fmt.Clone();

            // ICU4N TODO: Currency
            //// If we are creating a currency type formatter, then we may have to set the currency
            //// explicitly, since the actualLoc may be different than the desiredLocale
            //if (choice == NumberFormat.CURRENCYSTYLE ||
            //     choice == NumberFormat.ISOCURRENCYSTYLE ||
            //     choice == NumberFormat.PLURALCURRENCYSTYLE)
            //{
            //    fmt.SetCurrency(Currency.GetInstance(desiredLocale));
            //}

            UCultureInfo uloc = actualLoc;

            fmt.SetCulture(uloc, uloc); // services make no distinction between actual & valid
            return(fmt);
        }
Beispiel #13
0
        private void getFunctionalEquivalentTestCases(String path, Assembly cl, String resName, String keyword,
                                                      bool truncate, String[] testCases)
        {
            //String F_STR = "f";
            String T_STR = "t";

            bool[] isAvail = new bool[1];

            Logln("Testing functional equivalents...");
            for (int i = 0; i < testCases.Length; i += 3)
            {
                bool         expectAvail  = T_STR.Equals(testCases[i + 0]);
                UCultureInfo inLocale     = new UCultureInfo(testCases[i + 1]);
                UCultureInfo expectLocale = new UCultureInfo(testCases[i + 2]);

                Logln(((int)(i / 3)).ToString(CultureInfo.InvariantCulture) + ": " + expectAvail.ToString() + "\t\t" +
                      inLocale.ToString() + "\t\t" + expectLocale.ToString());

                UCultureInfo equivLocale = ICUResourceBundle.GetFunctionalEquivalent(path, cl, resName, keyword, inLocale, isAvail, truncate);
                bool         gotAvail    = isAvail[0];

                if ((gotAvail != expectAvail) || !equivLocale.Equals(expectLocale))
                {
                    Errln(((int)(i / 3)).ToString(CultureInfo.InvariantCulture) + ":  Error, expected  Equiv=" + expectAvail.ToString() + "\t\t" +
                          inLocale.ToString() + "\t\t--> " + expectLocale.ToString() + ",  but got " + gotAvail.ToString() + " " +
                          equivLocale.ToString());
                }
            }
        }
        /**
         * Verify the correct getLocale() behavior for the given service.
         * @param requestedLocale the locale to request.  This MUST BE
         * FAKE.  In other words, it should be something like
         * en_US_FAKEVARIANT so this method can verify correct fallback
         * behavior.
         * @param svc a factory object that can create the object to be
         * tested.
         * @param sub an object that can be used to retrieve a subobject
         * which should also be tested.  May be null.
         * @param reg an object that supplies the registration and
         * unregistration functionality to be tested.  May be null.
         */
        internal void CheckService(String requestedLocale, IServiceFacade svc,
                                   ISubobject sub, IRegistrar reg)
        {
            UCultureInfo req = new UCultureInfo(requestedLocale);
            Object       obj = svc.Create(req);

            CheckObject(requestedLocale, obj, "gt", "ge");
            if (sub != null)
            {
                Object subobj = sub.Get(obj);
                CheckObject(requestedLocale, subobj, "gt", "ge");
            }
            if (reg != null)
            {
                Logln("Info: Registering service");
                Object key    = reg.Register(req, obj);
                Object objReg = svc.Create(req);
                CheckObject(requestedLocale, objReg, "eq", "eq");
                if (sub != null)
                {
                    Object subobj = sub.Get(obj);
                    // Assume subobjects don't come from services, so
                    // their metadata should be structured normally.
                    CheckObject(requestedLocale, subobj, "gt", "ge");
                }
                Logln("Info: Unregistering service");
                if (!reg.Unregister(key))
                {
                    Errln("FAIL: unregister failed");
                }
                Object objUnreg = svc.Create(req);
                CheckObject(requestedLocale, objUnreg, "gt", "ge");
            }
        }
Beispiel #15
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, UCultureInfo locale, string tableName,
                                            string itemName, string defaultValue)
        {
            ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.
                                       GetBundleInstance(path, locale.Name);

            return(GetTableString(bundle, tableName, null, itemName, defaultValue));
        }
Beispiel #16
0
 public virtual void SetCulture(UCultureInfo ulocale) // ICU4N TODO: API - In general, formatters in .NET should be unaware of the culture unless it is explictly passed to the Format() method. Need to rework this.
 {
     if (ulocale == null)
     {
         ulocale = UCultureInfo.CurrentCulture;
     }
     Init(null, PluralType.Cardinal, ulocale, null);
 }
 internal override object RegisterInstance(Collator collator, UCultureInfo locale)
 {
     // Set the collator locales while registering so that getInstance()
     // need not guess whether the collator's locales are already set properly
     // (as they are by the data loader).
     collator.SetCulture(locale, locale);
     return(service.RegisterObject(collator, locale));
 }
Beispiel #18
0
 public void Init()
 {
     available = UCultureInfo.GetCultures(UCultureTypes.AllCultures);
     for (int i = 0; i < available.Length; i++)
     {
         availableMap[available[i].ToString()] = "";
     }
 }
Beispiel #19
0
 public override Collator CreateCollator(UCultureInfo loc)
 {
     if (map.TryGetValue(loc, out object cio) && cio is CollatorInfo ci && ci != null)
     {
         return(ci.collator);
     }
     return(null);
 }
Beispiel #20
0
        /**
         * Convenience override of getDisplayNames(UCultureInfo, Comparator, string) that
         * uses the current default UCultureInfo as the locale, the default collator for
         * the locale as the comparator to sort the display names, and null for
         * the matchID.
         */
        public IDictionary <string, string> GetDisplayNames(ICUService service)
        {
            UCultureInfo locale = UCultureInfo.CurrentCulture;
            //Collator col = Collator.getInstance(locale.toLocale());
            CompareInfo col = CompareInfo.GetCompareInfo(locale.ToCultureInfo().Name);

            return(service.GetDisplayNames(locale, col, null));
        }
Beispiel #21
0
 /// <summary>
 /// <icu/> Creates a <see cref="UResourceBundle"/> for the locale specified, from which users can extract
 /// resources by using their corresponding keys.
 /// </summary>
 /// <param name="locale">Specifies the locale for which we want to open the resource.
 /// If null the bundle for default locale is opened.</param>
 /// <returns>A resource bundle for the given <paramref name="locale"/>.</returns>
 /// <stable>ICU 3.0</stable>
 public static UResourceBundle GetBundleInstance(UCultureInfo locale)
 {
     if (locale == null)
     {
         locale = UCultureInfo.CurrentCulture;
     }
     return(GetBundleInstance(ICUData.IcuBaseName, locale.Name,
                              ICUResourceBundle.IcuDataAssembly, false));
 }
Beispiel #22
0
 /*
  * Initializes the <code>PluralRules</code> object.
  * Postcondition:<br/>
  *   <code>ulocale</code>    :  is <code>locale</code><br/>
  *   <code>pluralRules</code>:  if <code>rules</code> != <code>null</code>
  *                              it's set to rules, otherwise it is the
  *                              predefined plural rule set for the locale
  *                              <code>ulocale</code>.<br/>
  *   <code>parsedValues</code>: is <code>null</code><br/>
  *   <code>pattern</code>:      is <code>null</code><br/>
  *   <code>numberFormat</code>: a <code>NumberFormat</code> for the locale
  *                              <code>ulocale</code>.
  */
 private void Init(PluralRules rules, PluralType type, UCultureInfo locale, NumberFormat numberFormat)
 {
     ulocale     = locale;
     pluralRules = (rules == null) ? PluralRules.ForLocale(ulocale, type) // ICU4N TODO: Make extension method for UCultureInfo.GetPluralRules(PluralType)..?
                                   : rules;
     pluralRulesWrapper = new PluralSelectorAdapter(pluralRules);         // ICU4N: Have to pass a reference to pluralRules in the constructor
     ResetPattern();
     this.numberFormat = (numberFormat == null) ? NumberFormat.GetInstance(ulocale) : numberFormat;
 }
Beispiel #23
0
 /// <summary>
 /// Gets the <see cref="LocaleData"/> object associated with the <see cref="UCultureInfo"/> specified in <paramref name="locale"/>.
 /// </summary>
 /// <param name="locale"><see cref="UCultureInfo"/> with thich the locale data object is associated.</param>
 /// <returns>A locale data object.</returns>
 /// <stable>ICU 3.4</stable>
 public static LocaleData GetInstance(UCultureInfo locale)
 {
     return(new LocaleData
     {
         bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, locale),
         langBundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuLanguageBaseName, locale),
         noSubstitute = false
     });
 }
Beispiel #24
0
 /// <summary>
 /// Constructs a transliterator.
 /// </summary>
 public UppercaseTransliterator(UCultureInfo loc)
     : base(_ID, null)
 {
     locale     = loc;
     csp        = UCaseProperties.Instance;
     iter       = new ReplaceableContextEnumerator();
     result     = new StringBuilder();
     caseLocale = UCaseProperties.GetCaseLocale(locale);
 }
Beispiel #25
0
            public void TestLocaleGetCode(UCultureInfo testLocaleName, int expected)
            {
                int[] code = UScript.GetCode(testLocaleName);
                if (code == null)
                {
                    if (expected != UScript.InvalidCode)
                    {
                        Errln("Error testing UScript.getCode(). Got: null" + " Expected: " + expected + " for locale "
                              + testLocaleName);
                    }
                }
                else if ((code[0] != expected))
                {
                    Errln("Error testing UScript.getCode(). Got: " + code[0] + " Expected: " + expected + " for locale "
                          + testLocaleName);
                }

                UCultureInfo esperanto = new UCultureInfo("eo_DE");

                using (new ThreadCultureChange(esperanto, esperanto))
                {
                    code = UScript.GetCode(esperanto);
                    if (code != null)
                    {
                        if (code[0] != UScript.Latin)
                        {
                            Errln("Did not get the expected script code for Esperanto");
                        }
                    }
                    else
                    {
                        Warnln("Could not load the locale data.");
                    }
                }

                // Should work regardless of whether we have locale data for the language.
                AssertEqualScripts("tg script: Cyrl",  // Tajik
                                   new int[] { UScript.Cyrillic }, UScript.GetCode(new UCultureInfo("tg")));
                AssertEqualScripts("xsr script: Deva", // Sherpa
                                   new int[] { UScript.Devanagari }, UScript.GetCode(new UCultureInfo("xsr")));

                // Multi-script languages.
                AssertEqualScripts("ja scripts: Kana Hira Hani",
                                   new int[] { UScript.Katakana, UScript.Hiragana, UScript.Han }, UScript.GetCode(new UCultureInfo("ja")));
                AssertEqualScripts("ko scripts: Hang Hani", new int[] { UScript.Hangul, UScript.Han },
                                   UScript.GetCode(new UCultureInfo("ko")));
                AssertEqualScripts("zh script: Hani", new int[] { UScript.Han }, UScript.GetCode(new UCultureInfo("zh")));
                AssertEqualScripts("zh-Hant scripts: Hani Bopo", new int[] { UScript.Han, UScript.Bopomofo },
                                   UScript.GetCode(new UCultureInfo("zh_Hant")));
                AssertEqualScripts("zh-TW scripts: Hani Bopo", new int[] { UScript.Han, UScript.Bopomofo },
                                   UScript.GetCode(new UCultureInfo("zh_Hant_TW")));

                // Ambiguous API, but this probably wants to return Latin rather than Rongorongo (Roro).
                AssertEqualScripts("ro-RO script: Latn", new int[] { UScript.Latin }, UScript.GetCode("ro-RO")); // String
                                                                                                                 // not
                                                                                                                 // UCultureInfo
            }
Beispiel #26
0
        /// <summary>
        /// Return a snapshot of the mapping from display names to visible
        /// IDs for this service.  This set will not change as factories
        /// are added or removed, but the supported ids will, so there is
        /// no guarantee that all and only the ids in the returned map will
        /// be visible and supported by the service in subsequent calls,
        /// nor is there any guarantee that the current display names match
        /// those in the set.  The display names are sorted based on the
        /// comparer provided.
        /// </summary>
        public virtual IDictionary <string, string> GetDisplayNames(UCultureInfo locale, IComparer <string> com, string matchID)
        {
            IDictionary <string, string> dncache = null;
            LocaleRef reference = dnref;

            if (reference != null)
            {
                dncache = reference.Get(locale, com);
            }

            while (dncache == null)
            {
                lock (syncLock)
                {
                    if (reference == dnref || dnref == null)
                    {
                        dncache = new SortedDictionary <string, string>(com); // sorted

                        foreach (var e in GetVisibleIDMap())
                        {
                            string          id = e.Key;
                            IServiceFactory f  = e.Value;
                            dncache[f.GetDisplayName(id, locale)] = id;
                        }

                        dncache = dncache.AsReadOnly();
                        dnref   = new LocaleRef(dncache, locale, com);
                    }
                    else
                    {
                        reference = dnref;
                        dncache   = reference.Get(locale, com);
                    }
                }
            }

            ICUServiceKey matchKey = CreateKey(matchID);

            if (matchKey == null)
            {
                return(dncache.AsReadOnly());
            }

            // ICU4N: Rather than copying and then removing the items (which isn't allowed with
            // .NET iterators), we reverse the logic and add the items only if they are fallback.
            IDictionary <string, string> result = new SortedDictionary <string, string>(com);

            foreach (var e in dncache)
            {
                if (matchKey.IsFallbackOf(e.Value))
                {
                    result.Add(e.Key, e.Value);
                }
            }
            return(result);
        }
Beispiel #27
0
        public void TestGetFunctionalEquivalent()
        {
            var kw = Collator.Keywords;

            String[] DATA =
            {
                "sv",                          "sv",                    "t",
                "sv@collation=direct",         "sv",                    "t",
                "sv@collation=traditional",    "sv",                    "t",
                "sv@collation=gb2312han",      "sv",                    "t",
                "sv@collation=stroke",         "sv",                    "t",
                "sv@collation=pinyin",         "sv",                    "t",
                "sv@collation=standard",       "sv@collation=standard", "t",
                "sv@collation=reformed",       "sv",                    "t",
                "sv@collation=big5han",        "sv",                    "t",
                "sv_FI",                       "sv",                    "f",
                "sv_FI@collation=direct",      "sv",                    "f",
                "sv_FI@collation=traditional", "sv",                    "f",
                "sv_FI@collation=gb2312han",   "sv",                    "f",
                "sv_FI@collation=stroke",      "sv",                    "f",
                "sv_FI@collation=pinyin",      "sv",                    "f",
                "sv_FI@collation=standard",    "sv@collation=standard", "f",
                "sv_FI@collation=reformed",    "sv",                    "f",
                "sv_FI@collation=big5han",     "sv",                    "f",
                "nl",                          "root",                  "t",
                "nl@collation=direct",         "root",                  "t",
                "nl_BE",                       "root",                  "f",
                "nl_BE@collation=direct",      "root",                  "f",
                "nl_BE@collation=traditional", "root",                  "f",
                "nl_BE@collation=gb2312han",   "root",                  "f",
                "nl_BE@collation=stroke",      "root",                  "f",
                "nl_BE@collation=pinyin",      "root",                  "f",
                "nl_BE@collation=big5han",     "root",                  "f",
                "nl_BE@collation=phonebook",   "root",                  "f",
                "en_US_VALLEYGIRL",            "root",                  "f"
            };
            int DATA_COUNT = (DATA.Length / 3);

            for (int i = 0; i < DATA_COUNT; i++)
            {
                bool[]       isAvailable     = new bool[1];
                UCultureInfo input           = new UCultureInfo(DATA[(i * 3) + 0]);
                UCultureInfo expect          = new UCultureInfo(DATA[(i * 3) + 1]);
                bool         expectAvailable = DATA[(i * 3) + 2].Equals("t");
                UCultureInfo actual          = Collator.GetFunctionalEquivalent(kw[0], input, isAvailable);
                if (!actual.Equals(expect) || (expectAvailable != isAvailable[0]))
                {
                    Errln("#" + i + ": Collator.getFunctionalEquivalent(" + input + ")=" + actual + ", avail " + isAvailable[0] + ", " +
                          "expected " + expect + " avail " + expectAvailable);
                }
                else
                {
                    Logln("#" + i + ": Collator.getFunctionalEquivalent(" + input + ")=" + actual + ", avail " + isAvailable[0]);
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// Create a <see cref="LocaleKey"/> with canonical primary and fallback IDs.
        /// </summary>
        public static LocaleKey CreateWithCanonical(UCultureInfo locale, string canonicalFallbackID, int kind)
        {
            if (locale == null)
            {
                return(null);
            }
            string canonicalPrimaryID = locale.FullName;

            return(new LocaleKey(canonicalPrimaryID, canonicalPrimaryID, canonicalFallbackID, kind));
        }
Beispiel #29
0
        /// <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 = UCultureInfo.GetFullName(primaryID);

            return(new LocaleKey(primaryID, canonicalPrimaryID, canonicalFallbackID, kind));
        }
Beispiel #30
0
        internal static NumberingSystem LookupInstanceByLocale(LocaleLookupData localeLookupData)
        {
            UCultureInfo      locale = localeLookupData.locale;
            ICUResourceBundle rb;

            try
            {
                rb = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, locale);
                rb = rb.GetWithFallback("NumberElements");
            }
            catch (MissingManifestResourceException)
            {
                return(new NumberingSystem());
            }

            string numbersKeyword          = localeLookupData.numbersKeyword;
            string resolvedNumberingSystem = null;

            for (; ;)
            {
                try
                {
                    resolvedNumberingSystem = rb.GetStringWithFallback(numbersKeyword);
                    break;
                }
                catch (MissingManifestResourceException)
                { // Fall back behavior as defined in TR35
                    if (numbersKeyword.Equals("native") || numbersKeyword.Equals("finance"))
                    {
                        numbersKeyword = "default";
                    }
                    else if (numbersKeyword.Equals("traditional"))
                    {
                        numbersKeyword = "native";
                    }
                    else
                    {
                        break;
                    }
                }
            }

            NumberingSystem ns = null;

            if (resolvedNumberingSystem != null)
            {
                ns = GetInstanceByName(resolvedNumberingSystem);
            }

            if (ns == null)
            {
                ns = new NumberingSystem();
            }
            return(ns);
        }