libcore.icu.ICU Java Examples

The following examples show how to use libcore.icu.ICU. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Currency.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the <code>Currency</code> instance for the country of the
 * given locale. The language and variant components of the locale
 * are ignored. The result may vary over time, as countries change their
 * currencies. For example, for the original member countries of the
 * European Monetary Union, the method returns the old national currencies
 * until December 31, 2001, and the Euro from January 1, 2002, local time
 * of the respective countries.
 * <p>
 * The method returns <code>null</code> for territories that don't
 * have a currency, such as Antarctica.
 *
 * @param locale the locale for whose country a <code>Currency</code>
 * instance is needed
 * @return the <code>Currency</code> instance for the country of the given
 * locale, or {@code null}
 * @exception NullPointerException if <code>locale</code> or its country
 * code is {@code null}
 * @exception IllegalArgumentException if the country of the given {@code locale}
 * is not a supported ISO 3166 country code.
 */
public static Currency getInstance(Locale locale) {
    synchronized (localesToCurrencies) {
        if (locale == null) {
            throw new NullPointerException("locale == null");
        }
        Currency currency = localesToCurrencies.get(locale);
        if (currency != null) {
            return currency;
        }

        String currencyCode = ICU.getCurrencyCode(locale);
        if (currencyCode == null) {
            // Don't cache -- this is rarely necessary since most countries have currencies.
            if (Arrays.asList(Locale.getISOCountries()).contains(locale.getCountry())) {
                return null;
            }
            throw new IllegalArgumentException("Unsupported ISO 3166 country: " + locale);
        } else if (currencyCode.equals("XXX")) {
            return null;
        }
        Currency result = getInstance(currencyCode);
        localesToCurrencies.put(locale, result);
        return result;
    }
}
 
Example #2
Source File: Locale.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the name of this locale's country, localized to {@code locale}.
 * Returns the empty string if this locale does not correspond to a specific
 * country.
 */
public String getDisplayCountry(Locale locale) {
    String countryCode = baseLocale.getRegion();
    if (countryCode.isEmpty()) {
        return "";
    }

    final String normalizedRegion = normalizeAndValidateRegion(
            countryCode, false /* strict */);
    if (normalizedRegion.isEmpty()) {
        return countryCode;
    }

    String result = ICU.getDisplayCountry(this, locale);
    if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
        result = ICU.getDisplayCountry(this, Locale.getDefault());
    }
    return result;
}
 
Example #3
Source File: Locale.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a three-letter abbreviation for this locale's country.
 * If the country matches an ISO 3166-1 alpha-2 code, the
 * corresponding ISO 3166-1 alpha-3 uppercase code is returned.
 * If the locale doesn't specify a country, this will be the empty
 * string.
 *
 * <p>The ISO 3166-1 codes can be found on-line.
 *
 * @return A three-letter abbreviation of this locale's country.
 * @exception MissingResourceException Throws MissingResourceException if the
 * three-letter country abbreviation is not available for this locale.
 */
public String getISO3Country() throws MissingResourceException {
    // Android changed: Use.getIso3Country. Also return "" for missing regions.
    final String region = baseLocale.getRegion();
    // Note that this will return an UN.M49 region code
    if (region.length() == 3) {
        return baseLocale.getRegion();
    } else if (region.isEmpty()) {
        return "";
    }

    // Prefix "en-" because ICU doesn't really care about what the language is.
    String country3 = ICU.getISO3Country("en-" + region);
    if (!region.isEmpty() && country3.isEmpty()) {
        throw new MissingResourceException("Couldn't find 3-letter country code for "
                + baseLocale.getRegion(), "FormatData_" + toString(), "ShortCountry");
    }
    return country3;
}
 
Example #4
Source File: Locale.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a three-letter abbreviation of this locale's language.
 * If the language matches an ISO 639-1 two-letter code, the
 * corresponding ISO 639-2/T three-letter lowercase code is
 * returned.  The ISO 639-2 language codes can be found on-line,
 * see "Codes for the Representation of Names of Languages Part 2:
 * Alpha-3 Code".  If the locale specifies a three-letter
 * language, the language is returned as is.  If the locale does
 * not specify a language the empty string is returned.
 *
 * @return A three-letter abbreviation of this locale's language.
 * @exception MissingResourceException Throws MissingResourceException if
 * three-letter language abbreviation is not available for this locale.
 */
public String getISO3Language() throws MissingResourceException {
    // Android-changed: Use ICU.getIso3Language. Also return "" for empty languages
    // for the sake of backwards compatibility.
    String lang = baseLocale.getLanguage();
    if (lang.length() == 3) {
        return lang;
    } else if (lang.isEmpty()) {
        return "";
    }

    String language3 = ICU.getISO3Language(lang);
    if (!lang.isEmpty() && language3.isEmpty()) {
        throw new MissingResourceException("Couldn't find 3-letter language code for "
                + lang, "FormatData_" + toString(), "ShortLanguage");
    }

    return language3;
}
 
Example #5
Source File: ICUTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_localeFromString() throws Exception {
  // localeFromString is pretty lenient. Some of these can't be round-tripped
  // through Locale.toString.
  assertEquals(Locale.ENGLISH, ICU.localeFromIcuLocaleId("en"));
  assertEquals(Locale.ENGLISH, ICU.localeFromIcuLocaleId("en_"));
  assertEquals(Locale.ENGLISH, ICU.localeFromIcuLocaleId("en__"));
  assertEquals(Locale.US, ICU.localeFromIcuLocaleId("en_US"));
  assertEquals(Locale.US, ICU.localeFromIcuLocaleId("en_US_"));
  assertEquals(new Locale("", "US", ""), ICU.localeFromIcuLocaleId("_US"));
  assertEquals(new Locale("", "US", ""), ICU.localeFromIcuLocaleId("_US_"));
  assertEquals(new Locale("", "", "POSIX"), ICU.localeFromIcuLocaleId("__POSIX"));
  assertEquals(new Locale("aa", "BB", "CCCCC"), ICU.localeFromIcuLocaleId("aa_BB_CCCCC"));
}
 
Example #6
Source File: Currency.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the symbol of this currency for the specified locale.
 * For example, for the US Dollar, the symbol is "$" if the specified
 * locale is the US, while for other locales it may be "US$". If no
 * symbol can be determined, the ISO 4217 currency code is returned.
 *
 * @param locale the locale for which a display name for this currency is
 * needed
 * @return the symbol of this currency for the specified locale
 * @exception NullPointerException if <code>locale</code> is null
 */
public String getSymbol(Locale locale) {
    if (locale == null) {
        throw new NullPointerException("locale == null");
    }
    // Check the locale first, in case the locale has the same currency.
    LocaleData localeData = LocaleData.get(locale);
    if (localeData.internationalCurrencySymbol.equals(currencyCode)) {
        return localeData.currencySymbol;
    }

    // Try ICU, and fall back to the currency code if ICU has nothing.
    String symbol = ICU.getCurrencySymbol(locale, currencyCode);
    return symbol != null ? symbol : currencyCode;
}
 
Example #7
Source File: Currency.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static LinkedHashSet<String> constructAvailableCurrencyCodes() {
    LinkedHashSet<String> result = new LinkedHashSet<String>();
    for (String code : ICU.getAvailableCurrencyCodes()) {
      result.add(code);
    }
    return result;
}
 
Example #8
Source File: Locale.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the full variant name in the specified {@code Locale} for the variant code
 * of this {@code Locale}. If there is no matching variant name, the variant code is
 * returned.
 *
 * @since 1.7
 */
public String getDisplayVariant(Locale locale) {
    String variantCode = baseLocale.getVariant();
    if (variantCode.isEmpty()) {
        return "";
    }

    try {
        normalizeAndValidateVariant(variantCode);
    } catch (IllformedLocaleException ilfe) {
        return variantCode;
    }

    String result = ICU.getDisplayVariant(this, locale);
    if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
        result = ICU.getDisplayVariant(this, Locale.getDefault());
    }

    // The "old style" locale constructors allow us to pass in variants that aren't
    // valid BCP-47 variant subtags. When that happens, toLanguageTag will not emit
    // them. Note that we know variantCode.length() > 0 due to the isEmpty check at
    // the beginning of this function.
    if (result.isEmpty()) {
        return variantCode;
    }
    return result;
}
 
Example #9
Source File: Locale.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the name of this locale's script code, localized to {@link Locale}. If the
 * script code is unknown, the return value of this method is the same as that of
 * {@link #getScript()}.
 *
 * @since 1.7
 */
public String getDisplayScript(Locale locale) {
    String scriptCode = baseLocale.getScript();
    if (scriptCode.isEmpty()) {
        return "";
    }

    String result = ICU.getDisplayScript(this, locale);
    if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
        result = ICU.getDisplayScript(this, Locale.getDefault());
    }

    return result;

}
 
Example #10
Source File: Locale.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the name of this locale's language, localized to {@code locale}.
 * If the language name is unknown, the language code is returned.
 */
public String getDisplayLanguage(Locale locale) {
    String languageCode = baseLocale.getLanguage();
    if (languageCode.isEmpty()) {
        return "";
    }

    // Hacks for backward compatibility.
    //
    // Our language tag will contain "und" if the languageCode is invalid
    // or missing. ICU will then return "langue indéterminée" or the equivalent
    // display language for the indeterminate language code.
    //
    // Sigh... ugh... and what not.
    final String normalizedLanguage = normalizeAndValidateLanguage(
            languageCode, false /* strict */);
    if (UNDETERMINED_LANGUAGE.equals(normalizedLanguage)) {
        return languageCode;
    }

    // TODO: We need a new hack or a complete fix for http://b/8049507 --- We would
    // cover the frameworks' tracks when they were using "tl" instead of "fil".
    String result = ICU.getDisplayLanguage(this, locale);
    if (result == null) { // TODO: do we need to do this, or does ICU do it for us?
        result = ICU.getDisplayLanguage(this, Locale.getDefault());
    }
    return result;
}
 
Example #11
Source File: DatePickerSpinnerDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Reorders the spinners according to the date format that is
 * explicitly set by the user and if no such is set fall back
 * to the current locale's default format.
 */
private void reorderSpinners() {
    mSpinners.removeAllViews();
    // We use numeric spinners for year and day, but textual months. Ask icu4c what
    // order the user's locale uses for that combination. http://b/7207103.
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "yyyyMMMdd");
    char[] order = ICU.getDateFormatOrder(pattern);
    final int spinnerCount = order.length;
    for (int i = 0; i < spinnerCount; i++) {
        switch (order[i]) {
            case 'd':
                mSpinners.addView(mDaySpinner);
                setImeOptions(mDaySpinner, spinnerCount, i);
                break;
            case 'M':
                mSpinners.addView(mMonthSpinner);
                setImeOptions(mMonthSpinner, spinnerCount, i);
                break;
            case 'y':
                mSpinners.addView(mYearSpinner);
                setImeOptions(mYearSpinner, spinnerCount, i);
                break;
            default:
                throw new IllegalArgumentException(Arrays.toString(order));
        }
    }
}
 
Example #12
Source File: System.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private static Properties initUnchangeableSystemProperties() {
    VMRuntime runtime = VMRuntime.getRuntime();
    Properties p = new Properties();

    // Set non-static properties.
    p.put("java.boot.class.path", runtime.bootClassPath());
    p.put("java.class.path", runtime.classPath());

    // TODO: does this make any sense? Should we just leave java.home unset?
    String javaHome = getenv("JAVA_HOME");
    if (javaHome == null) {
        javaHome = "/system";
    }
    p.put("java.home", javaHome);

    p.put("java.vm.version", runtime.vmVersion());

    try {
        StructPasswd passwd = Libcore.os.getpwuid(Libcore.os.getuid());
        p.put("user.name", passwd.pw_name);
    } catch (ErrnoException exception) {
        throw new AssertionError(exception);
    }

    StructUtsname info = Libcore.os.uname();
    p.put("os.arch", info.machine);
    if (p.get("os.name") != null && !p.get("os.name").equals(info.sysname)) {
        logE("Wrong compile-time assumption for os.name: " + p.get("os.name") + " vs " +
                info.sysname);
        p.put("os.name", info.sysname);
    }
    p.put("os.version", info.release);

    // Android-added: Undocumented properties that exist only on Android.
    p.put("android.icu.library.version", ICU.getIcuVersion());
    p.put("android.icu.unicode.version", ICU.getUnicodeVersion());
    p.put("android.icu.cldr.version", ICU.getCldrVersion());

    // Property override for ICU4J : this is the location of the ICU4C data. This
    // is prioritized over the properties in ICUConfig.properties. The issue with using
    // that is that it doesn't play well with jarjar and it needs complicated build rules
    // to change its default value.
    String icuDataPath = TimeZoneDataFiles.generateIcuDataPath();
    p.put("android.icu.impl.ICUBinary.dataPath", icuDataPath);

    parsePropertyAssignments(p, specialProperties());

    // Override built-in properties with settings from the command line.
    // Note: it is not possible to override hardcoded values.
    parsePropertyAssignments(p, runtime.properties());


    // Set static hardcoded properties.
    // These come last, as they must be guaranteed to agree with what a backend compiler
    // may assume when compiling the boot image on Android.
    for (String[] pair : AndroidHardcodedSystemProperties.STATIC_PROPERTIES) {
        if (p.containsKey(pair[0])) {
            logE("Ignoring command line argument: -D" + pair[0]);
        }
        if (pair[1] == null) {
            p.remove(pair[0]);
        } else {
            p.put(pair[0], pair[1]);
        }
    }

    return p;
}
 
Example #13
Source File: ICUTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void test_getAvailableLocales() throws Exception {
  // Check that corrupting our array doesn't affect other callers.
  assertNotNull(ICU.getAvailableLocales()[0]);
  ICU.getAvailableLocales()[0] = null;
  assertNotNull(ICU.getAvailableLocales()[0]);
}
 
Example #14
Source File: ICUTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void test_getISOCountries() throws Exception {
  // Check that corrupting our array doesn't affect other callers.
  assertNotNull(ICU.getISOCountries()[0]);
  ICU.getISOCountries()[0] = null;
  assertNotNull(ICU.getISOCountries()[0]);
}
 
Example #15
Source File: ICUTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void test_getISOLanguages() throws Exception {
  // Check that corrupting our array doesn't affect other callers.
  assertNotNull(ICU.getISOLanguages()[0]);
  ICU.getISOLanguages()[0] = null;
  assertNotNull(ICU.getISOLanguages()[0]);
}
 
Example #16
Source File: DateFormat.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an array of all locales for which the
 * <code>get*Instance</code> methods of this class can return
 * localized instances.
 * The returned array represents the union of locales supported by the Java
 * runtime and by installed
 * {@link java.text.spi.DateFormatProvider DateFormatProvider} implementations.
 * It must contain at least a <code>Locale</code> instance equal to
 * {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>DateFormat</code> instances are available.
 */
public static Locale[] getAvailableLocales()
{
    /* J2ObjC: java.text.spi is not provided.
    LocaleServiceProviderPool pool =
        LocaleServiceProviderPool.getPool(DateFormatProvider.class);
    return pool.getAvailableLocales();*/
    return ICU.getAvailableDateFormatLocales();
}
 
Example #17
Source File: DateFormatSymbols.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an array of all locales for which the
 * <code>getInstance</code> methods of this class can return
 * localized instances.
 * The returned array represents the union of locales supported by the
 * Java runtime and by installed
 * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
 * implementations.  It must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>DateFormatSymbols</code> instances are available.
 * @since 1.6
 */
public static Locale[] getAvailableLocales() {
    /* J2ObjC: java.text.spi is not provided.
    LocaleServiceProviderPool pool=
        LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class);
    return pool.getAvailableLocales();*/
    return ICU.getAvailableDateFormatSymbolsLocales();
}
 
Example #18
Source File: NumberFormat.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an array of all locales for which the
 * <code>get*Instance</code> methods of this class can return
 * localized instances.
 * The returned array represents the union of locales supported by the Java
 * runtime and by installed
 * {@link java.text.spi.NumberFormatProvider NumberFormatProvider} implementations.
 * It must contain at least a <code>Locale</code> instance equal to
 * {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>NumberFormat</code> instances are available.
 */
public static Locale[] getAvailableLocales() {
    /* J2ObjC: java.text.spi is not provided.
    LocaleServiceProviderPool pool =
        LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
    return pool.getAvailableLocales();*/
    return ICU.getAvailableNumberFormatLocales();
}
 
Example #19
Source File: Currency.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the default number of fraction digits used with this currency.
 * For example, the default number of fraction digits for the Euro is 2,
 * while for the Japanese Yen it's 0.
 * In the case of pseudo-currencies, such as IMF Special Drawing Rights,
 * -1 is returned.
 *
 * @return the default number of fraction digits used with this currency
 */
public int getDefaultFractionDigits() {
    // In some places the code XXX is used as the fall back currency.
    // The RI returns -1, but ICU defaults to 2 for unknown currencies.
    if (currencyCode.equals("XXX")) {
        return -1;
    }
    return ICU.getCurrencyFractionDigits(currencyCode);
}
 
Example #20
Source File: Locale.java    From j2objc with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the default locale for this instance of the Java Virtual Machine.
 * This does not affect the host locale.
 * <p>
 * If there is a security manager, its <code>checkPermission</code>
 * method is called with a <code>PropertyPermission("user.language", "write")</code>
 * permission before the default locale is changed.
 * <p>
 * The Java Virtual Machine sets the default locale during startup
 * based on the host environment. It is used by many locale-sensitive
 * methods if no locale is explicitly specified.
 * <p>
 * Since changing the default locale may affect many different areas
 * of functionality, this method should only be used if the caller
 * is prepared to reinitialize locale-sensitive code running
 * within the same Java Virtual Machine.
 * <p>
 * By setting the default locale with this method, all of the default
 * locales for each Category are also set to the specified default locale.
 *
 * @throws SecurityException
 *        if a security manager exists and its
 *        <code>checkPermission</code> method doesn't allow the operation.
 * @throws NullPointerException if <code>newLocale</code> is null
 * @param newLocale the new default locale
 * @see SecurityManager#checkPermission
 * @see java.util.PropertyPermission
 */
public static synchronized void setDefault(Locale newLocale) {
    setDefault(Category.DISPLAY, newLocale);
    setDefault(Category.FORMAT, newLocale);
    defaultLocale = newLocale;
    ICU.setDefaultLocale(newLocale.toLanguageTag());
}
 
Example #21
Source File: DecimalFormatSymbols.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the
 * <code>getInstance</code> methods of this class can return
 * localized instances.
 *
 * @return an array of locales for which localized
 *         <code>DecimalFormatSymbols</code> instances are available.
 * @since 1.6
 */
public static Locale[] getAvailableLocales() {
    // Android-changed: Removed used of DecimalFormatSymbolsProvider. Switched to use ICU.
    return ICU.getAvailableLocales();
}
 
Example #22
Source File: Collator.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of locales for which custom {@code Collator} instances
 * are available.
 * <p>Note that Android does not support user-supplied locale service providers.
 */
public static Locale[] getAvailableLocales() {
    return ICU.getAvailableLocales();
}
 
Example #23
Source File: DateFormat.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the current date format stored as a char array. Returns a 3 element
 * array containing the day ({@code 'd'}), month ({@code 'M'}), and year ({@code 'y'}))
 * in the order specified by the user's format preference.  Note that this order is
 * <i>only</i> appropriate for all-numeric dates; spelled-out (MEDIUM and LONG)
 * dates will generally contain other punctuation, spaces, or words,
 * not just the day, month, and year, and not necessarily in the same
 * order returned here.
 */
public static char[] getDateFormatOrder(Context context) {
    return ICU.getDateFormatOrder(getDateFormatString(context));
}
 
Example #24
Source File: DateFormat.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the best possible localized form of the given skeleton for the given
 * locale. A skeleton is similar to, and uses the same format characters as, a Unicode
 * <a href="http://www.unicode.org/reports/tr35/#Date_Format_Patterns">UTS #35</a>
 * pattern.
 *
 * <p>One difference is that order is irrelevant. For example, "MMMMd" will return
 * "MMMM d" in the {@code en_US} locale, but "d. MMMM" in the {@code de_CH} locale.
 *
 * <p>Note also in that second example that the necessary punctuation for German was
 * added. For the same input in {@code es_ES}, we'd have even more extra text:
 * "d 'de' MMMM".
 *
 * <p>This method will automatically correct for grammatical necessity. Given the
 * same "MMMMd" input, this method will return "d LLLL" in the {@code fa_IR} locale,
 * where stand-alone months are necessary. Lengths are preserved where meaningful,
 * so "Md" would give a different result to "MMMd", say, except in a locale such as
 * {@code ja_JP} where there is only one length of month.
 *
 * <p>This method will only return patterns that are in CLDR, and is useful whenever
 * you know what elements you want in your format string but don't want to make your
 * code specific to any one locale.
 *
 * @param locale the locale into which the skeleton should be localized
 * @param skeleton a skeleton as described above
 * @return a string pattern suitable for use with {@link java.text.SimpleDateFormat}.
 */
public static String getBestDateTimePattern(Locale locale, String skeleton) {
    return ICU.getBestDateTimePattern(skeleton, locale);
}
 
Example #25
Source File: Currency.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the name that is suitable for displaying this currency for
 * the specified locale.  If there is no suitable display name found
 * for the specified locale, the ISO 4217 currency code is returned.
 *
 * @param locale the locale for which a display name for this currency is
 * needed
 * @return the display name of this currency for the specified locale
 * @exception NullPointerException if <code>locale</code> is null
 * @since 1.7
 */
public String getDisplayName(Locale locale) {
    return ICU.getCurrencyDisplayName(locale, currencyCode);
}
 
Example #26
Source File: Locale.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of all 2-letter language codes defined in ISO 639.
 * Can be used to create Locales.
 * <p>
 * <b>Note:</b>
 * <ul>
 * <li>ISO 639 is not a stable standard&mdash; some languages' codes have changed.
 * The list this function returns includes both the new and the old codes for the
 * languages whose codes have changed.
 * <li>The <code>Locale</code> class also supports language codes up to
 * 8 characters in length.  Therefore, the list returned by this method does
 * not contain ALL valid codes that can be used to create Locales.
 * </ul>
 */
public static String[] getISOLanguages() {
    // Android-changed: Use ICU.
    return ICU.getISOLanguages();
}
 
Example #27
Source File: Locale.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of all 2-letter country codes defined in ISO 3166.
 * Can be used to create Locales.
 * <p>
 * <b>Note:</b> The <code>Locale</code> class also supports other codes for
 * country (region), such as 3-letter numeric UN M.49 area codes.
 * Therefore, the list returned by this method does not contain ALL valid
 * codes that can be used to create Locales.
 */
public static String[] getISOCountries() {
    // Android-changed: Use ICU.
    return ICU.getISOCountries();
}
 
Example #28
Source File: Locale.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of all installed locales.
 * The returned array represents the union of locales supported
 * by the Java runtime environment and by installed
 * {@link java.util.spi.LocaleServiceProvider LocaleServiceProvider}
 * implementations.  It must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of installed locales.
 */
public static Locale[] getAvailableLocales() {
    // J2ObjC changed: Switched to use ICU. (Android has the same change at master)
    return ICU.getAvailableLocales();
}