Refine search
/** * Determine the RFC 3066 compliant language tag, * as used for the HTTP "Accept-Language" header. * @param locale the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as {@code String} * @deprecated as of 5.0.4, in favor of {@link Locale#toLanguageTag()} */ @Deprecated public static String toLanguageTag(Locale locale) { return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : ""); }
/** * Resolves locale code from locale. */ public static String resolveLocaleCode(Locale locale) { return resolveLocaleCode(locale.getLanguage(), locale.getCountry(), locale.getVariant()); }
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));
// may contain simple syntax error, i dont have java rite now to test.. // but this is a bigger picture for ur algo... public String localeToString(Locale l) { return l.getLanguage() + "," + l.getCountry(); } public Locale stringToLocale(String s) { StringTokenizer tempStringTokenizer = new StringTokenizer(s,","); if(tempStringTokenizer.hasMoreTokens()) String l = tempStringTokenizer.nextElement(); if(tempStringTokenizer.hasMoreTokens()) String c = tempStringTokenizer.nextElement(); return new Locale(l,c); }
String[] locales = Locale.getISOCountries(); for (String countryCode : locales) { Locale obj = new Locale("", countryCode); System.out.println("Country Code = " + obj.getCountry() + ", Country Name = " + obj.getDisplayCountry()); }
/** * <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; }
/** * 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; }
/** * Determine the RFC 3066 compliant language tag, * as used for the HTTP "Accept-Language" header. * @param locale the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as {@code String} * @deprecated as of 5.0.4, in favor of {@link Locale#toLanguageTag()} */ @Deprecated public static String toLanguageTag(Locale locale) { return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : ""); }
@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(); } };
public static Tuple2<String,Locale> toLocaleModel(String baseName,Locale locale) { if (StringKit.isBlank(baseName)) { return new Tuple2<>("i18n_"+locale.getLanguage()+"_"+locale.getCountry(),locale); }else { String[] baseNames = pattern.split(baseName); if (baseNames != null && baseNames.length == 3) { return new Tuple2<>(baseName,new Locale(baseNames[1],baseNames[2])); } throw new IllegalArgumentException("baseName illegal,name format is :i18n_{language}_{country}.properties," + "for example:i18n_zh_CN.properties"); } }
m_locale = new Locale(langValue.toLowerCase(), Locale.getDefault().getCountry());
/** * <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; }
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(), ""));
public static String toLocale(Locale locale) { return locale.getLanguage() + "_" + locale.getCountry(); } }
String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuilder temp = new StringBuilder(basename);
public static Tuple2<String,Locale> toLocaleModel(String baseName,Locale locale) { if (StringKit.isBlank(baseName)) { return new Tuple2<>("i18n_"+locale.getLanguage()+"_"+locale.getCountry(),locale); }else { String[] baseNames = pattern.split(baseName); if (baseNames != null && baseNames.length == 3) { return new Tuple2<>(baseName,new Locale(baseNames[1],baseNames[2])); } throw new IllegalArgumentException("baseName illegal,name format is :i18n_{language}_{country}.properties," + "for example:i18n_zh_CN.properties"); } }
m_locale = new Locale(langValue.toLowerCase(), Locale.getDefault().getCountry());
/** * 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; } }
/** * 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); }
/** * Determine the RFC 3066 compliant language tag, * as used for the HTTP "Accept-Language" header. * @param locale the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as String */ public static String toLanguageTag(Locale locale) { return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : ""); }