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:Main.java

/**
 * @return the string for the given locale, translating
 * Android deprecated language codes into the modern ones
 * used by Chromium.//from ww  w . j  a  v a  2 s .  c  om
 */
public static String getLocale(Locale locale) {
    String language = locale.getLanguage();
    String country = locale.getCountry();

    // Android uses deprecated lanuages codes for Hebrew and Indonesian but Chromium uses the
    // updated codes. Also, Android uses "tl" while Chromium uses "fil" for Tagalog/Filipino.
    // So apply a mapping.
    // See http://developer.android.com/reference/java/util/Locale.html
    if ("iw".equals(language)) {
        language = "he";
    } else if ("in".equals(language)) {
        language = "id";
    } else if ("tl".equals(language)) {
        language = "fil";
    }
    return country.isEmpty() ? language : language + "-" + country;
}

From source file:Main.java

public static String getLanguageCode(Locale locale) {
    String languageCode = locale.getLanguage();
    if (!locale.getCountry().isEmpty()) {
        languageCode += "-" + locale.getCountry();
    }// w  ww  . ja v a2 s  . co m
    return languageCode;
}

From source file:Main.java

public static String getLanguageEnv() {
    Locale l = Locale.getDefault();
    String language = l.getLanguage();
    String country = l.getCountry().toLowerCase();
    if ("zh".equalsIgnoreCase(language)) {
        if ("cn".equals(country)) {
            language = "zh-CN";
        } else if ("tw".equals(country)) {
            language = "zh-TW";
        }/*from  www.j a  va  2s  .  c o  m*/
    }
    return language;
}

From source file:Main.java

public static int getLanguageValue() {
    int lang = 0;
    Locale l = Locale.getDefault();
    String language = l.getLanguage();
    String country = l.getCountry().toLowerCase();
    if ("zh".equalsIgnoreCase(language)) {
        if ("cn".equals(country)) {
            lang = 1;//from ww  w  . j  ava2s . co  m
        } else if ("tw".equals(country)) {
            lang = 3;
        }
    } else {
        lang = 2;
    }
    return lang;
}

From source file:net.sourceforge.fenixedu.util.phd.InstitutionPhdCandidacyProcessProperties.java

static private String readLanguageCode(final Locale locale) {
    String country = locale.getCountry();
    String language = locale.getLanguage();

    String result = null;/*from  ww  w .  j  av a 2 s . c  o  m*/
    if (!StringUtils.isEmpty(language)) {
        result = language.toUpperCase();
    } else if (!StringUtils.isEmpty(country)) {
        result = country.toUpperCase();
    }

    if (!StringUtils.isEmpty(result)) {
        return result;
    }

    return "PT";
}

From source file:Main.java

public static void printLocaleDetails(Locale locale) {
    String languageCode = locale.getLanguage();
    String languageName = locale.getDisplayLanguage();
    String countryCode = locale.getCountry();
    String countryName = locale.getDisplayCountry();
    // Print the locale info
    System.out.println("Language: " + languageName + "(" + languageCode + "); " + "Country: " + countryName
            + "(" + countryCode + ")");
}

From source file:ListOfCitys.CityList.java

private static String getCountryName(String zone) throws IOException {
    String[] arry = zone.split(";"); //EU;DE
    zone = arry[1];//from   w w  w.j av a2  s  .  c om
    String[] locales = Locale.getISOCountries();
    String countryName = "";
    JSONArray countryWithCities = new JSONArray();
    Map<String, List<String>> countryWithCityNames = new HashMap<>();
    for (String countryCode : locales) {
        Locale obj = new Locale("", countryCode);
        System.out
                .println("Country Code = " + obj.getCountry() + ", Country Name = " + obj.getDisplayCountry());
        countryWithCities.add(getCityNameForCountry(obj.getCountry(), countryCode));
        if (obj.getCountry().equalsIgnoreCase(zone)) {
            countryName = obj.getDisplayCountry();
            break;
        }
    }
    System.out.println("-----json array --- " + countryWithCities.toJSONString());
    try (FileWriter file = new FileWriter("test.json")) {
        file.write(countryWithCities.toJSONString());
    }
    return countryName;
}

From source file:Main.java

/**
 * 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
 *///from ww w  .  j a v a  2s  .c  om
public static String toLanguageTag(Locale locale) {
    return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : "");
}

From source file:Main.java

/**
 * Create acceptLanguage.//from   www.  j  av  a 2s .  c  o m
 *
 * @return Returns the client can accept the language types. Such as:zh-CN,zh.
 */
public static String systemAcceptLanguage() {
    if (TextUtils.isEmpty(acceptLanguageInstance)) {
        Locale locale = Locale.getDefault();
        String language = locale.getLanguage();
        String country = locale.getCountry();
        StringBuilder acceptLanguageBuilder = new StringBuilder(language);
        if (!TextUtils.isEmpty(country))
            acceptLanguageBuilder.append('-').append(country).append(',').append(language);
        acceptLanguageInstance = acceptLanguageBuilder.toString();
    }
    return acceptLanguageInstance;
}

From source file:com.enonic.cms.business.localization.resource.LocalizationResourceBundleUtils.java

public static String createLocaleString(Locale locale) {
    String localeString = locale.getLanguage();

    return StringUtils.isNotEmpty(locale.getCountry()) ? localeString + "-" + locale.getCountry()
            : localeString;//from   w  w  w.jav  a  2  s .  c  om
}