Refine search
@Override public final String convert(final Locale o) { final StringBuilder value = new StringBuilder(o.getLanguage()); if (!o.getCountry().isEmpty() || !o.getVariant().isEmpty()) { value.append("-").append(o.getCountry()); } if (!o.getVariant().isEmpty()) { value.append("-").append(o.getVariant()); } return value.toString(); //JDK7+: return o.toLanguageTag(); } };
/** * <p>Obtains the list of languages supported for a given country.</p> * * <p>This method takes a country code and searches to find the * languages available for that country. Variant locales are removed.</p> * * @param countryCode the 2 letter country code, null returns empty * @return an unmodifiable List of Locale objects, not null */ public static List<Locale> languagesByCountry(final String countryCode) { if (countryCode == null) { return Collections.emptyList(); } List<Locale> langs = cLanguagesByCountry.get(countryCode); if (langs == null) { langs = new ArrayList<>(); final List<Locale> locales = availableLocaleList(); for (final Locale locale : locales) { if (countryCode.equals(locale.getCountry()) && locale.getVariant().isEmpty()) { langs.add(locale); } } langs = Collections.unmodifiableList(langs); cLanguagesByCountry.putIfAbsent(countryCode, langs); langs = cLanguagesByCountry.get(countryCode); } return langs; }
public void setCountry(String country) { // Grab the old locale Locale oldLocale = getLocale(); // Create a new one Locale newLocale = new Locale(oldLocale.getLanguage(), country, oldLocale.getVariant()); setLocale(newLocale); }
/** * Resolves locale code from locale. */ public static String resolveLocaleCode(Locale locale) { return resolveLocaleCode(locale.getLanguage(), locale.getCountry(), locale.getVariant()); }
/** * <p>Obtains the list of languages supported for a given country.</p> * * <p>This method takes a country code and searches to find the * languages available for that country. Variant locales are removed.</p> * * @param countryCode the 2 letter country code, null returns empty * @return an unmodifiable List of Locale objects, never null */ public static List languagesByCountry(String countryCode) { List langs = (List) cLanguagesByCountry.get(countryCode); //syncd if (langs == null) { if (countryCode != null) { langs = new ArrayList(); List locales = availableLocaleList(); for (int i = 0; i < locales.size(); i++) { Locale locale = (Locale) locales.get(i); if (countryCode.equals(locale.getCountry()) && locale.getVariant().length() == 0) { langs.add(locale); } } langs = Collections.unmodifiableList(langs); } else { langs = Collections.EMPTY_LIST; } cLanguagesByCountry.put(countryCode, langs); //syncd } return langs; }
String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuilder temp = new StringBuilder(basename);
/** * Returns the {@code Currency} instance for this {@code Locale}'s country. * @throws IllegalArgumentException * if the locale's country is not a supported ISO 3166 country. */ public static Currency getInstance(Locale locale) { synchronized (localesToCurrencies) { Currency currency = localesToCurrencies.get(locale); if (currency != null) { return currency; } String country = locale.getCountry(); String variant = locale.getVariant(); if (!variant.isEmpty() && (variant.equals("EURO") || variant.equals("HK") || variant.equals("PREEURO"))) { country = country + "_" + variant; } String currencyCode = ICU.getCurrencyCode(country); if (currencyCode == 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; } }
String lang = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant();
public void setLanguage(String language) { // Grab the old locale Locale oldLocale = getLocale(); // Create a new one Locale newLocale = new Locale(language, oldLocale.getCountry(), oldLocale.getVariant()); setLocale(newLocale); }
/** * Returns a locale that's one less specific, or {@code null} if there's no less specific locale. */ public static Locale getLessSpecificLocale(Locale locale) { String country = locale.getCountry(); if (locale.getVariant().length() != 0) { String language = locale.getLanguage(); return country != null ? new Locale(language, country) : new Locale(language); } if (country.length() != 0) { return new Locale(locale.getLanguage()); } return null; }
if (locale != null) { list.add(locale); if (!locale.getVariant().isEmpty()) { list.add(new Locale(locale.getLanguage(), locale.getCountry())); if (!locale.getCountry().isEmpty()) { list.add(new Locale(locale.getLanguage(), StringUtils.EMPTY));
/** * <p>Obtains the list of countries supported for a given language.</p> * * <p>This method takes a language code and searches to find the * countries available for that language. Variant locales are removed.</p> * * @param languageCode the 2 letter language code, null returns empty * @return an unmodifiable List of Locale objects, not null */ public static List<Locale> countriesByLanguage(final String languageCode) { if (languageCode == null) { return Collections.emptyList(); } List<Locale> countries = cCountriesByLanguage.get(languageCode); if (countries == null) { countries = new ArrayList<>(); final List<Locale> locales = availableLocaleList(); for (final Locale locale : locales) { if (languageCode.equals(locale.getLanguage()) && !locale.getCountry().isEmpty() && locale.getVariant().isEmpty()) { countries.add(locale); } } countries = Collections.unmodifiableList(countries); cCountriesByLanguage.putIfAbsent(languageCode, countries); countries = cCountriesByLanguage.get(languageCode); } return countries; }
if (locale != null) { list.add(locale); if (locale.getVariant().length() > 0) { list.add(new Locale(locale.getLanguage(), locale.getCountry())); if (locale.getCountry().length() > 0) { list.add(new Locale(locale.getLanguage(), ""));
/** * Returns a locale with the most-specific field removed, or null if this * locale had an empty language, country and variant. */ private static Locale strip(Locale locale) { String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (!variant.isEmpty()) { variant = ""; } else if (!country.isEmpty()) { country = ""; } else if (!language.isEmpty()) { language = ""; } else { return null; } return new Locale(language, country, variant); }
/** * Return the resource file suffic for the indicated locale * For most locales, this will be based the language code. However * for Chinese, we do distinguish between Taiwan and PRC * * @param locale the locale * @return an String suffix which canbe appended to a resource name */ private static final String getResourceSuffix(Locale locale) { String lang = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); String suffix = "_" + locale.getLanguage(); if (lang.equals("zh")) suffix += "_" + country; if (country.equals("JP")) suffix += "_" + country + "_" + variant; return suffix; }
for (int i = 0; i < locales.size(); i++) { Locale locale = (Locale) locales.get(i); if (languageCode.equals(locale.getLanguage()) && locale.getCountry().length() != 0 && locale.getVariant().length() == 0) { countries.add(locale);
String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuilder temp = new StringBuilder(basename);
String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant();
String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant();
private static Calendar createCalendar(TimeZone zone, Locale aLocale) { // If the specified locale is a Thai locale, returns a BuddhistCalendar // instance. if ("th".equals(aLocale.getLanguage()) && ("TH".equals(aLocale.getCountry()))) { return new sun.util.BuddhistCalendar(zone, aLocale); } else if ("JP".equals(aLocale.getVariant()) && "JP".equals(aLocale.getCountry()) && "ja".equals(aLocale.getLanguage())) { return new JapaneseImperialCalendar(zone, aLocale); } // else create the default calendar return new GregorianCalendar(zone, aLocale); }