Code example for Locale

Methods: getCountry, getLanguage

0
 
    /** 
     * Construct the language code (hl= paramater) for the given locale. 
     */ 
    public static String getLanguage(Locale locale) {
        String language = locale.getLanguage();
        StringBuilder hl = new StringBuilder(language);
        String country = locale.getCountry();
 
        if (!TextUtils.isEmpty(country) && useLangCountryHl(language, country)) {
            hl.append('-');
            hl.append(country);
        } 
 
        if (DBG) Log.d(TAG, "language " + language + ", country " + country + " -> hl=" + hl);
        return hl.toString();
    } 
 
    // TODO: This is a workaround for bug 3232296. When that is fixed, this method can be removed. 
    private static boolean useLangCountryHl(String language, String country) {
        // lang-country is currently only supported for a small number of locales