List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:architecture.common.util.LocaleUtils.java
public static List<Locale> getCandidateLocales(Locale locale) { if (cachedCandidateLocales.containsKey(locale)) return cachedCandidateLocales.get(locale); List<Locale> results = new ArrayList<Locale>(); results.add(locale);//w w w.j a v a 2 s. c om if (locale.getVariant().length() > 0) results.add(new Locale(locale.getLanguage(), locale.getCountry())); if (locale.getCountry().length() > 0) results.add(new Locale(locale.getLanguage())); results = Collections.unmodifiableList(results); cachedCandidateLocales.put(locale, results); return results; }
From source file:com.googlecode.l10nmavenplugin.model.PropertiesFileUtils.java
/** * Parent locale , ex: en_US => en/*from www . ja v a2s.c om*/ * * @param locale * @return null if no parent locale */ public static Locale getParentLocale(Locale locale) { Locale parentLocale = null; if (locale != null) { String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (!StringUtils.isEmpty(language)) { if (!StringUtils.isEmpty(variant)) { parentLocale = new Locale(language, country); } else if (!StringUtils.isEmpty(country)) { parentLocale = new Locale(language); } } } return parentLocale; }
From source file:no.kantega.commons.util.LocaleLabels.java
private static String getLocaleName(Locale locale) { StringBuilder loc = new StringBuilder(locale.getLanguage()); if (isNotBlank(locale.getCountry())) { loc.append("_").append(locale.getCountry()); }/*from w ww .j a v a 2 s . c om*/ if (isNotBlank(locale.getVariant())) { loc.append("_").append(locale.getVariant()); } return loc.toString(); }
From source file:LocaleMap.java
public static String getString(Locale locale) { boolean hasLanguage = !locale.getLanguage().equals(""); boolean hasCountry = !locale.getCountry().equals(""); boolean hasVariant = !locale.getVariant().equals(""); if (hasLanguage && hasCountry && hasVariant) return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant(); else if (hasLanguage && hasCountry) return locale.getLanguage() + '-' + locale.getCountry(); else if (hasLanguage) return locale.getLanguage(); else/*from ww w . j a va 2 s . c om*/ return ""; }
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Applies this language code to be the new language of the program. */// w w w . j a v a 2 s . c o m public static void setLocale(Locale locale) { ApplicationSettings.LANGUAGE.setValue(locale.getLanguage()); ApplicationSettings.COUNTRY.setValue(locale.getCountry()); ApplicationSettings.LOCALE_VARIANT.setValue(locale.getVariant()); GUIMediator.resetLocale(); }
From source file:com.astamuse.asta4d.util.i18n.LocalizeUtil.java
public static String[] getCandidatePaths(String path, Locale locale) { int dotIndex = path.lastIndexOf("."); String name = dotIndex > 0 ? path.substring(0, dotIndex) : path; String extension = dotIndex > 0 ? path.substring(dotIndex) : StringUtils.EMPTY; List<String> candidatePathList = new ArrayList<>(); if (!StringUtils.isEmpty(locale.getVariant())) { candidatePathList.add(name + '_' + locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant() + extension); }/*from w w w . java 2 s . co m*/ if (!StringUtils.isEmpty(locale.getCountry())) { candidatePathList.add(name + '_' + locale.getLanguage() + "_" + locale.getCountry() + extension); } if (!StringUtils.isEmpty(locale.getLanguage())) { candidatePathList.add(name + '_' + locale.getLanguage() + extension); } candidatePathList.add(path); return candidatePathList.toArray(new String[candidatePathList.size()]); }
From source file:LocaleUtils.java
/** * <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 *//*from w w w .j a va2 s.c o m*/ 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; }
From source file:LocaleUtils.java
/** * <p>Obtains the list of locales to search through when performing * a locale search.</p>//from w ww .j ava 2s . c om * * <pre> * localeLookupList(Locale("fr", "CA", "xxx"), Locale("en")) * = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr"), Locale("en"] * </pre> * * <p>The result list begins with the most specific locale, then the * next more general and so on, finishing with the default locale. * The list will never contain the same locale twice.</p> * * @param locale the locale to start from, null returns empty list * @param defaultLocale the default locale to use if no other is found * @return the unmodifiable list of Locale objects, 0 being locale, never null */ public static List localeLookupList(Locale locale, Locale defaultLocale) { List list = new ArrayList(4); 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(), "")); } if (list.contains(defaultLocale) == false) { list.add(defaultLocale); } } return Collections.unmodifiableList(list); }
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Returns true, if <code>locale</code> is less specific than the system * default locale.//w ww.ja v a2 s. co m * * @see Locale#getDefault() */ public static boolean matchesDefaultLocale(Locale locale) { Locale systemLocale = Locale.getDefault(); if (matchesOrIsMoreSpecific(systemLocale.getLanguage(), locale.getLanguage()) && matchesOrIsMoreSpecific(systemLocale.getCountry(), locale.getCountry()) && matchesOrIsMoreSpecific(systemLocale.getVariant(), locale.getVariant())) { return true; } return false; }
From source file:LocaleUtils.java
/** * <p>Obtains the list of countries supported for a given language.</p> * /* w w w. ja v a 2s . c om*/ * <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, never null */ public static List countriesByLanguage(String languageCode) { List countries = (List) cCountriesByLanguage.get(languageCode); //syncd if (countries == null) { if (languageCode != null) { countries = new ArrayList(); List locales = availableLocaleList(); 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); } } countries = Collections.unmodifiableList(countries); } else { countries = Collections.EMPTY_LIST; } cCountriesByLanguage.put(languageCode, countries); //syncd } return countries; }