List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Returns true, if <code>locale</code> is less specific than the system * default locale./*w w w . j a v a 2 s .c om*/ * * @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 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 . ja v a 2 s. co 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:com.carlomicieli.jtrains.value.objects.LocalizedField.java
private static String sanitizeLanguage(String lang) { Locale l = Locale.forLanguageTag(lang); if (!ISOValidationUtils.countryIsValid(l.getCountry())) { throw new IllegalArgumentException("'" + lang + "' is not a valid locale code (country)."); }/* w w w . j a va 2 s. c om*/ if (!ISOValidationUtils.languageIsValid(l.getLanguage())) { throw new IllegalArgumentException("'" + lang + "' is not a valid locale code (language)."); } return l.getLanguage(); }
From source file:LocaleUtils.java
/** * <p>Obtains the list of countries supported for a given language.</p> * //from w ww .jav a 2 s. co m * <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; }
From source file:com.googlecode.osde.internal.gadgets.parser.GadgetXmlSerializer.java
private static Object createLocales(Module module) { StringBuilder sb = new StringBuilder(); ModulePrefs modulePrefs = module.getModulePrefs(); List<Locale> locales = modulePrefs.getLocales(); for (Locale locale : locales) { sb.append(" <Locale"); createAttribute("lang", locale.getLang(), sb); createAttribute("country", locale.getCountry(), sb); createAttribute("messages", locale.getMessages(), sb); List<Msg> msgs = locale.getInlineMessages(); if (msgs != null && !msgs.isEmpty()) { sb.append(">\n"); for (Msg msg : msgs) { sb.append(" <msg name=\"" + msg.getName() + "\">" + escape(msg.getContent()) + "</msg>\n"); }/* w ww .ja v a 2 s. c om*/ sb.append(" </Locale>\n"); } else { sb.append(" />\n"); } } return sb.toString(); }
From source file:com.adjust.sdk.Util.java
private static String getCountry(final Locale locale) { final String country = locale.getCountry(); return sanitizeStringShort(country); }
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);//from ww w .j a v a 2s. co m 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:edu.ku.brc.af.core.SchemaI18NService.java
/** * Only Loads the Locales with empty Country and Variant *//* w ww .ja va2 s . com*/ public static void initializeLocales() { SchemaI18NService srv = getInstance(); if (srv != null) { Vector<Locale> locs = srv.getLocales(); if (locs.size() == 0) { for (Locale locale : Locale.getAvailableLocales()) { if (StringUtils.isNotEmpty(locale.getCountry())) { locs.add(locale); } } Collections.sort(locs, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); } } }
From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java
public static List<TranslationInfo> sortByLocale(List<TranslationInfo> translations) { Collections.sort(translations, new Comparator<TranslationInfo>() { @Override/*from w w w . j av a 2 s . com*/ public int compare(TranslationInfo translation1, TranslationInfo translation2) { // first compares with user's default locale final Locale userLocale = Locale.getDefault(); final String userLanguage = userLocale.getLanguage().toLowerCase(); final String userCountry = userLocale.getCountry().toLowerCase(); final String[] fields1 = translation1.language.split("_"); final String[] fields2 = translation2.language.split("_"); final int score1 = compareLocale(fields1[0], fields1[1], userLanguage, userCountry); final int score2 = compareLocale(fields2[0], fields2[1], userLanguage, userCountry); int r = score2 - score1; if (r != 0) return r; // then sorts by language & name r = translation1.language.compareTo(translation2.language); return r == 0 ? translation1.name.compareTo(translation2.name) : r; } }); return translations; }
From source file:org.jahia.taglibs.functions.Functions.java
public static String getLangIcon(Locale localeToDisplay) { if ("".equals(localeToDisplay.getCountry())) return "flag_" + localeToDisplay.getLanguage().toLowerCase() + "_on"; else/* www .j ava 2 s .com*/ return "flag_" + Patterns.SPACE.matcher(localeToDisplay.getDisplayCountry(Locale.ENGLISH).toLowerCase()) .replaceAll("_"); }