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.cnr.icar.eric.client.xml.registry.infomodel.InternationalStringImpl.java

/**
 * Calculate the possible keys List for a locale/charset pair. Candidate keys
 * are://from  w  w  w  .  j a  v  a2 s .co  m
 * <ul>
 * <li> charset + "_" + language + "_" + country + "_" + variant
 * <li> charset + "_" + language + "_" + countryi
 * <li> charset + "_" + language
 * </ul>
 *
 * Candidate keys where the final component is an empty string are omitted.
 * For example, if country is an empty string, the second candidate key is omitted.
 *
 * @param charset the charset name
 * @param locale the locale
 * @return List with the keys along the search path.
 */
private static List<String> calculateKeys(Locale locale, String charset) {
    final ArrayList<String> result = new ArrayList<String>(3);
    final String language = locale.getLanguage();
    final int languageLength = language.length();
    final String country = locale.getCountry();
    final int countryLength = country.length();
    final String variant = locale.getVariant();
    final int variantLength = variant.length();

    if ((languageLength + countryLength + variantLength) == 0) {
        //The locale is "", "", "".
        return result;
    }

    final StringBuffer temp = new StringBuffer(charset);
    temp.append('_');
    temp.append(language);

    if (languageLength > 0) {
        result.add(0, temp.toString());
    }

    if ((countryLength + variantLength) == 0) {
        return result;
    }

    temp.append('_');
    temp.append(country);

    if (countryLength > 0) {
        result.add(0, temp.toString());
    }

    if (variantLength == 0) {
        return result;
    }

    temp.append('_');
    temp.append(variant);
    result.add(0, temp.toString());

    return result;
}

From source file:org.jahia.utils.LanguageCodeConverters.java

/**
 * Returns a language tags encoded (RFC 3066) compliant string from
 * a Java Locale object. Note that Locales without any languages will
 * not be accepted by this method and will return a null String since
 * language tags MUST contain a language
 *
 * @param locale the locale we want to be converted.
 *
 * @return a String containing the RFC 3066 encoded language information
 * extracted from the tag. If their is no language found in the locale a
 * NULL string is returned instead !/*from   www.j av a  2s.  c o m*/
 */
public static String localeToLanguageTag(Locale locale) {
    StringBuilder result = new StringBuilder();
    if (!("".equals(locale.getLanguage()))) {
        result.append(locale.getLanguage());
    } else {
        // if there is no language we can't return a valid
        // language tag.
        return null;
    }
    if (!("".equals(locale.getCountry()))) {
        result.append("-");
        result.append(locale.getCountry());
    }
    if (!("".equals(locale.getVariant()))) {
        result.append("-");
        result.append(locale.getVariant());
    }

    return result.toString();
}

From source file:org.libreplan.web.common.ConfigurationModel.java

private static Map<String, String> getAllCurrencies() {
    Map<String, String> currencies = new TreeMap<>();
    for (Locale locale : Locale.getAvailableLocales()) {
        if (StringUtils.isNotBlank(locale.getCountry())) {
            Currency currency = Currency.getInstance(locale);
            currencies.put(currency.getCurrencyCode(), currency.getSymbol(locale));
        }//from  www.j ava2 s .com
    }
    return currencies;
}

From source file:org.apache.tiles.xmlDefinition.I18nFactorySet.java

/**
 * Calculate the postixes along the search path from the base bundle to the
 * bundle specified by baseName and locale.
 * Method copied from java.util.ResourceBundle
 * @param baseName the base bundle name/*from ww w . ja v a2 s  .c  o  m*/
 * @param locale the locale
 */
private static List calculatePostixes(String baseName, Locale locale) {
    final List result = new ArrayList(MAX_BUNDLES_SEARCHED);
    final String language = locale.getLanguage();
    final int languageLength = language.length();
    final String country = locale.getCountry();
    final int countryLength = country.length();
    final String variant = locale.getVariant();
    final int variantLength = variant.length();

    if (languageLength + countryLength + variantLength == 0) {
        //The locale is "", "", "".
        return result;
    }

    final StringBuffer temp = new StringBuffer(baseName);
    temp.append('_');
    temp.append(language);

    if (languageLength > 0)
        result.add(temp.toString());

    if (countryLength + variantLength == 0)
        return result;

    temp.append('_');
    temp.append(country);

    if (countryLength > 0)
        result.add(temp.toString());

    if (variantLength == 0) {
        return result;
    } else {
        temp.append('_');
        temp.append(variant);
        result.add(temp.toString());
        return result;
    }
}

From source file:com.microsoft.alm.plugin.context.soap.CatalogServiceImpl.java

private static String localeToRFC5646LanguageTag(final Locale locale) throws IllegalArgumentException {

    // language[-variant][-region]

    String result = locale.getLanguage();

    if (locale.getVariant().length() > 0) {
        result = result + "-" + locale.getVariant(); //$NON-NLS-1$
    }/*from w w  w  . j a v  a 2  s  . c om*/

    if (locale.getCountry().length() > 0) {
        result = result + "-" + locale.getCountry(); //$NON-NLS-1$
    }

    return result;
}

From source file:org.microg.gms.auth.login.LoginActivity.java

private static String buildUrl(String tmpl, Locale locale) {
    return Uri.parse(EMBEDDED_SETUP_URL).buildUpon().appendQueryParameter("source", "android")
            .appendQueryParameter("xoauth_display_name", "Android Device")
            .appendQueryParameter("lang", locale.getLanguage())
            .appendQueryParameter("cc", locale.getCountry().toLowerCase(Locale.US))
            .appendQueryParameter("langCountry", locale.toString().toLowerCase(Locale.US))
            .appendQueryParameter("hl", locale.toString().replace("_", "-")).appendQueryParameter("tmpl", tmpl)
            .build().toString();//from www . j a  va  2s.  c  o  m
}

From source file:org.anoopam.main.common.AMServiceRequest.java

/**
 * obtains the device Country from the Device Local
 * @return//  w  w w  .j a  va 2 s  . c  om
 */
public static String getDeviceCountry() {
    Locale deviceLocal = AMApplication.getInstance().getApplicationContext().getResources()
            .getConfiguration().locale;
    String deviceCountry = "COULD NOT OBTAIN";

    if (deviceLocal != null) {
        deviceCountry = deviceLocal.getCountry();
    }
    return deviceCountry;
}

From source file:com.salesmanager.core.util.ShippingUtil.java

/**
 * Builds a Map<String,String> of services available (id, code) example
 * 01-EXPRESS SHIPPING//from www.ja v a 2  s . co  m
 * 
 * @param serviceline
 * @param moduleid
 * @param locale
 * @return
 */
public static Map<String, String> buildServiceMapByCode(String moduleid, Locale locale) throws Exception {

    ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    String country = locale.getCountry();
    if (locale.getVariant().equals("EUR")) {
        country = "X1";
    }

    ModuleConfiguration serviceconfig = rservice.getModuleConfiguration(moduleid, "service", country);

    if (serviceconfig == null) {
        serviceconfig = rservice.getModuleConfiguration(moduleid, "service", "XX");// generic
    }

    if (serviceconfig == null) {
        throw new Exception(
                "ModuleConfiguration does not exist for " + moduleid + "-service-XX-" + locale.getCountry());
    }

    String serviceline = serviceconfig.getConfigurationValue();

    Map returnmap = getConfigurationMap(serviceline, ";", "|");

    return returnmap;

}

From source file:com.salesmanager.core.util.ShippingUtil.java

/**
 * Builds a Map<String,String> of services avilables ID, CODE from the
 * service .properties file//from   w w  w  .ja v a2 s .c o  m
 * 
 * @param serviceline
 * @param moduleid
 * @param locale
 * @return
 */
public static Map<String, String> buildServiceMap(String moduleid, Locale locale) throws Exception {

    ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    String country = locale.getCountry();
    if (locale.getVariant().equals("EUR")) {
        country = "X1";
    }

    ModuleConfiguration serviceconfig = rservice.getModuleConfiguration(moduleid, "service", country);

    if (serviceconfig == null) {
        serviceconfig = rservice.getModuleConfiguration(moduleid, "service", "XX");// generic
    }

    if (serviceconfig == null) {
        throw new Exception("ModuleConfiguration does not exist for " + moduleid + "-service-XX-" + country);
    }

    String serviceline = serviceconfig.getConfigurationValue();

    ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale);

    List pkgids = getConfigurationList(serviceline);

    // List returnlist = new ArrayList();
    Map returnmap = new HashMap();

    Iterator it = pkgids.iterator();
    while (it.hasNext()) {
        String pkgid = (String) it.next();
        String pkg = bundle.getString("shipping.quote.services.label." + pkgid);
        returnmap.put(pkgid, pkg);
    }

    // return returnlist;
    return returnmap;
}

From source file:com.salesmanager.core.util.ShippingUtil.java

/**
 * Builds a Map<String,String> of services available (id, label example
 * 01-EXPRESS SHIPPING// w  w w. j  av  a  2s  . co m
 * 
 * @param serviceline
 * @param moduleid
 * @param locale
 * @return
 */
public static Map<String, String> buildServiceMapLabelByCode(String moduleid, Locale locale) throws Exception {

    ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    String country = locale.getCountry();
    if (locale.getVariant().equals("EUR")) {
        country = "X1";
    }

    ModuleConfiguration serviceconfig = rservice.getModuleConfiguration(moduleid, "service", country);

    if (serviceconfig == null) {
        serviceconfig = rservice.getModuleConfiguration(moduleid, "service", "XX");// generic
    }

    if (serviceconfig == null) {
        throw new Exception(
                "ModuleConfiguration does not exist for " + moduleid + "-service-XX-" + locale.getCountry());
    }

    String serviceline = serviceconfig.getConfigurationValue();

    Map amap = getConfigurationMap(serviceline, ";", "|");
    Map returnMap = new HashMap();

    ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale);

    if (amap != null) {
        Iterator i = amap.keySet().iterator();
        while (i.hasNext()) {
            String key = (String) i.next();
            String pkg = bundle.getString("shipping.quote.services.label." + key);
            returnMap.put(key, pkg);

        }
    }

    return returnMap;

}