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:de.onyxbits.raccoon.gplay.PlayManager.java

/**
 * Create a connection object for accessing Google Play, using an arbitrary
 * profile/*from   w  w  w  .  j a v a 2  s. c o m*/
 * 
 * @param profile
 *          the profile to use for connecting
 * @return a connection according to the submitted profile
 */
public static GooglePlayAPI createConnection(PlayProfile profile) {
    GooglePlayAPI ret = new GooglePlayAPI(profile.getUser(), profile.getPassword());
    ret.setUseragent(profile.getAgent());
    ret.setAndroidID(profile.getGsfId());
    ret.setToken(profile.getToken());
    Locale l = Locale.getDefault();
    String s = l.getLanguage();
    if (l.getCountry() != null) {
        s = s + "-" + l.getCountry();
    }
    ret.setLocalization(s);
    try {
        HttpClient proxy = createProxyClient(profile);
        if (proxy != null) {
            ret.setClient(proxy);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ret;
}

From source file:Main.java

/**
 * Test for lax Locale equality. More precisely, returns true if
 * (a) both are equal; (b) general only specifies language, and
 * specific has the same language; (c) general specifies language and
 * country, and specific has the same language and country. Else returns false.
 *///from ww w  .ja v a2s  . com
public static boolean subsumes(Locale general, Locale specific) {
    if (general == null || specific == null)
        return false;
    if (general.equals(specific))
        return true;
    else if (general.getVariant().equals("")) {
        if (general.getCountry().equals("")) {
            if (general.getLanguage().equals(specific.getLanguage()))
                return true;
        } else {
            if (general.getLanguage().equals(specific.getLanguage())
                    && general.getCountry().equals(specific.getCountry()))
                return true;
        }
    }
    return false;
}

From source file:com.googlecode.l10nmavenplugin.model.PropertiesFileUtils.java

/**
 * Parent locale , ex: en_US => en//from ww  w .j a  va 2s .c om
 * 
 * @param locale
 * @return null if no parent locale
 */
public static Locale getParentLocale(Locale locale) {
    Locale parentLocale = null;
    if (locale != null) {
        String language = locale.getLanguage();
        String country = locale.getCountry();
        String variant = locale.getVariant();

        if (!StringUtils.isEmpty(language)) {
            if (!StringUtils.isEmpty(variant)) {
                parentLocale = new Locale(language, country);
            } else if (!StringUtils.isEmpty(country)) {
                parentLocale = new Locale(language);
            }
        }
    }
    return parentLocale;
}

From source file:org.mozilla.gecko.Locales.java

/**
 * Gecko uses locale codes like "es-ES", whereas a Java {@link Locale}
 * stringifies as "es_ES"./*from w  w  w .j  a  v a2  s . co m*/
 *
 * This method approximates the Java 7 method
 * <code>Locale#toLanguageTag()</code>.
 *
 * @return a locale string suitable for passing to Gecko.
 */
public static String getLanguageTag(final Locale locale) {
    // If this were Java 7:
    // return locale.toLanguageTag();

    final String language = getLanguage(locale);
    final String country = locale.getCountry(); // Can be an empty string.
    if (country.equals("")) {
        return language;
    }
    return language + "-" + country;
}

From source file:de.jfachwert.post.PLZ.java

private static String toLandeskennung(Locale locale) {
    String country = locale.getCountry().toUpperCase();
    switch (country) {
    case "AT":
    case "DE":
        return country.substring(0, 1);
    default:/*from w ww.  j  a  v  a 2s .c  o m*/
        return country;
    }
}

From source file:Main.java

/**
 * Generate a User-Agent used in HTTP request to pick an ad.
 * Source used from Android source code "frameworks/base/core/java/android/webkit/WebSettings.java"
 * /*from  w ww . j a  v a2  s  .c  o  m*/
 * @return
 */
protected static String getUA() {
    if (UA != null)
        return UA;

    StringBuffer arg = new StringBuffer();

    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        arg.append(version);
    } else {
        arg.append("1.0");
    }
    arg.append("; ");

    final Locale l = Locale.getDefault();
    final String language = l.getLanguage();
    if (language != null) {
        arg.append(language.toLowerCase());
        final String country = l.getCountry();
        if (country != null) {
            arg.append("-");
            arg.append(country.toLowerCase());
        }
    } else {
        arg.append("de");
    }
    final String model = Build.MODEL;
    if (model.length() > 0) {
        arg.append("; ");
        arg.append(model);
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        arg.append(" Build/");
        arg.append(id);
    }

    // TODO: add version detection for AppleWebKit, Version and Safari
    final String rawUA = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2";
    UA = String.format(rawUA, arg);

    return UA;
}

From source file:Main.java

/**
 * Generate a User-Agent used in HTTP request to pick an ad. Source used
 * from Android source code/*from   w  w  w  . j  ava2s.  co m*/
 * "frameworks/base/core/java/android/webkit/WebSettings.java"
 * 
 * @return
 */
public static String getUA() {
    if (sUA != null)
        return sUA;

    StringBuffer arg = new StringBuffer();

    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        arg.append(version);
    } else {
        arg.append("1.0");
    }
    arg.append("; ");

    final Locale l = Locale.getDefault();
    final String language = l.getLanguage();
    if (language != null) {
        arg.append(language.toLowerCase());
        final String country = l.getCountry();
        if (country != null) {
            arg.append("-");
            arg.append(country.toLowerCase());
        }
    } else {
        arg.append("de");
    }
    final String model = Build.MODEL;
    if (model.length() > 0) {
        arg.append("; ");
        arg.append(model);
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        arg.append(" Build/");
        arg.append(id);
    }

    // TODO: add version detection for AppleWebKit, Version and Safari
    final String rawUA = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2";
    sUA = String.format(rawUA, arg);

    return sUA;
}

From source file:org.mifos.framework.util.helpers.LabelTagUtils.java

public static String getUserPreferredLocaleHelper(UserContext userContext) {
    String userPreferredLocale = null;
    if (null != userContext) {
        Locale locale = userContext.getCurrentLocale();
        if (null != locale) {
            userPreferredLocale = locale.getLanguage() + "_" + locale.getCountry();
        }// w  w w  .  j a v  a  2  s. com

    }
    return userPreferredLocale;
}

From source file:com.limegroup.gnutella.gui.LanguageUtils.java

/**
 * Applies this language code to be the new language of the program.
 *//* w w  w .j  a  v a2 s  . co m*/
public static void setLocale(Locale locale) {
    ApplicationSettings.LANGUAGE.setValue(locale.getLanguage());
    ApplicationSettings.COUNTRY.setValue(locale.getCountry());
    ApplicationSettings.LOCALE_VARIANT.setValue(locale.getVariant());

    GUIMediator.resetLocale();
}

From source file:count.ly.messaging.DeviceInfo.java

/**
 * Returns the current locale (ex. "en_US").
 *///from   www  .  j  av  a  2 s.  c  o  m
static String getLocale() {
    final Locale locale = Locale.getDefault();
    return locale.getLanguage() + "_" + locale.getCountry();
}