Example usage for java.util Locale getCountry

List of usage examples for java.util Locale getCountry

Introduction

In this page you can find the example usage for java.util Locale getCountry.

Prototype

public String getCountry() 

Source Link

Document

Returns the country/region code for this locale, which should either be the empty string, an uppercase ISO 3166 2-letter code, or a UN M.49 3-digit code.

Usage

From source file:it.vige.greenarea.geo.GoogleGis.java

public GoogleGis(Locale l) {
        locale = l.getCountry();
    }

From source file:com.enonic.cms.core.localization.LocalizationResourceBundleServiceImpl.java

private LocalizationResourceBundle createResourceBundle(final Locale locale,
        final ResourceKey defaultLocalizationResourceKey) {
    Properties props = new Properties();

    String lang = locale.getLanguage();
    String country = locale.getCountry();
    String variant = locale.getVariant();

    props.putAll(loadBundle(defaultLocalizationResourceKey, ""));

    if (StringUtils.isNotEmpty(lang)) {
        lang = lang.toLowerCase();//  w  w  w .j a va  2s  .  c  o  m
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang));
    }

    if (StringUtils.isNotEmpty(country)) {
        country = country.toLowerCase();
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country));
    }

    if (StringUtils.isNotEmpty(variant)) {
        variant = variant.toLowerCase();
        props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country + "_" + variant));
    }

    return new LocalizationResourceBundle(props);
}

From source file:org.apache.struts.tiles.TestTilesPlugin.java

/**
 * String representation of a Locale. A bug in the
 * Locale.toString() method results in Locales with
 * just a variant being incorrectly displayed.
 *///from   ww w.jav a 2 s  .c  om
private String print(Locale locale) {

    return locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant();
}

From source file:org.smigo.species.vernacular.JdbcVernacularDao.java

@Override
public List<Vernacular> getVernacularsByLocale(Locale locale) {
    //if country exists and matches, sort first, else by id
    final String sql = "SELECT * FROM VERNACULARS WHERE LANGUAGE = ? ORDER BY COUNTRY = ? OR ?='' DESC, ID;";
    return jdbcTemplate.query(sql, vernacularRowMapper, locale.getLanguage(), locale.getCountry(),
            locale.getCountry());// w ww.  java2 s .  co m
}

From source file:de.iew.services.impl.MessageBundleServiceImpl.java

protected String messageBundleKey(Locale locale, String basename) {
    return messageBundleKey(locale.getLanguage(), locale.getCountry(), basename);
}

From source file:org.businessmanager.geodb.OpenGeoDBImpl.java

public List<Country> getListOfCountries(String language) {
    List<Country> countries = null;

    if (language == null) {
        countries = countryMap.get(Locale.getDefault().getLanguage());
    } else {/*w  w  w .j  a  v a 2 s .co m*/
        countries = countryMap.get(language);
    }

    if (countries == null) {
        countries = new ArrayList<Country>();
    } else {
        return countries;
    }

    List<String> codes = new ArrayList<String>();
    Locale[] locales = Locale.getAvailableLocales();
    for (Locale locale : locales) {
        String code = locale.getCountry();

        // do not insert a country more than once
        if (codes.contains(code)) {
            continue;
        }

        String name = null;
        if (language != null) {
            name = locale.getDisplayCountry(Locale.forLanguageTag(language));
        } else {
            name = locale.getDisplayCountry();
        }

        if (!"".equals(code) && !"".equals(name)) {
            countries.add(new Country(code, name));
            codes.add(code);
        }
    }

    Collections.sort(countries, Country.getComparator());
    Country defaultCountry = findDefaultCountry(countries);
    if (defaultCountry != null) {
        countries.add(0, defaultCountry);
    }

    if (language == null) {
        countryMap.put(Locale.getDefault().getLanguage(), countries);
    } else {
        countryMap.put(language, countries);
    }

    return countries;
}

From source file:org.sakaiproject.adminsiteperms.tool.ResourceLoaderMessageSource.java

protected MessageFormat resolveCode(String code, Locale locale) {
    if (locale != null && resourceLoader.getLocale() == null) {
        resourceLoader.setContextLocale(locale);
    } else {//from   w  w  w  .  jav  a  2  s.  c  o  m
        locale = resourceLoader.getLocale();
    }
    String msg;
    if ("DEBUG".equals(locale.getVariant()) || "XX".equals(locale.getCountry())) {
        msg = "** " + code + " **";
    } else {
        msg = resourceLoader.getString(code);
    }
    if (log.isTraceEnabled())
        log.trace("MSG resolveCode: " + code + " (" + locale.getLanguage() + "_" + locale.getCountry()
                + (locale.getVariant() == null ? "" : " -" + locale.getVariant()) + ") into msg: " + msg);
    return createMessageFormat(msg, locale);
}

From source file:org.sakaiproject.adminsiteperms.tool.ResourceLoaderMessageSource.java

protected String resolveCodeWithoutArguments(String code, Locale locale) {
    if (locale != null && resourceLoader.getLocale() == null) {
        resourceLoader.setContextLocale(locale);
    } else {/*  w  ww .  j a va2s.  c om*/
        locale = resourceLoader.getLocale();
    }
    String msg;
    if ("DEBUG".equals(locale.getVariant()) || "XX".equals(locale.getCountry())) {
        msg = "** " + code + " **";
    } else {
        msg = resourceLoader.getString(code);
    }
    if (log.isTraceEnabled())
        log.trace("MSG resolveCode (noargs): " + code + " (" + locale.getLanguage() + "_" + locale.getCountry()
                + (locale.getVariant() == null ? "" : " -" + locale.getVariant()) + ") into msg: " + msg);
    return msg;
}

From source file:org.apache.click.extras.control.CountrySelect.java

/**
 * Load the Country Select options if not defined, using all the available
 * countries. The option value will be the two letter uppercase ISO name of
 * the country as the value and the localized country name as the label.
 *//*from  www. jav a 2 s .  c  o  m*/
protected void loadOptionList() {
    List optionList = getOptionList();

    // Determine whether option list should be loaded
    if (optionList.size() == 1) {
        Option option = (Option) optionList.get(0);
        if (option.getValue().equals(Option.EMPTY_OPTION.getValue())) {
            // Continue and load option list

        } else {
            // Don't load list
            return;
        }

    } else if (optionList.size() > 1) {
        // Don't load list
        return;
    }

    Set<Option> countryList = new TreeSet<Option>(new OptionLabelComparator(getLocale()));

    String[] isoCountries = Locale.getISOCountries();

    Locale userLocale = getLocale();

    for (int i = 0; i < isoCountries.length; i++) {
        Locale tmpLocale = new Locale("en", isoCountries[i]);
        final String iso = tmpLocale.getCountry();
        final String country = tmpLocale.getDisplayCountry(userLocale);

        if (StringUtils.isNotEmpty(iso) && StringUtils.isNotEmpty(country)) {
            countryList.add(new Option(iso, country));
        }
    }

    if (isRequired() && optionList.isEmpty()) {
        add(Option.EMPTY_OPTION);
    }

    addAll(countryList);
}

From source file:org.lockss.util.TestMetadataUtil.java

void assertLocale(String lang, String country, Locale l) {
    assertEquals("Language", lang, l.getLanguage());
    assertEquals("Country", country, l.getCountry());
}