Example usage for java.util Locale getLanguage

List of usage examples for java.util Locale getLanguage

Introduction

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

Prototype

public String getLanguage() 

Source Link

Document

Returns the language code of this Locale.

Usage

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

/**
 * Returns the current locale (ex. "en_US").
 *//*ww  w .  j  ava2s .  co m*/
static String getLocale() {
    final Locale locale = Locale.getDefault();
    return locale.getLanguage() + "_" + locale.getCountry();
}

From source file:Main.java

/**
 * <p>Obtains the list of locales to search through when performing
 * a locale search.</p>/*from w  ww  .  j  a  v a  2s  .  c o  m*/
 *
 * <pre>
 * localeLookupList(Locale("fr", "CA", "xxx"), Locale("en"))
 *   = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr"), Locale("en"]
 * </pre>
 *
 * <p>The result list begins with the most specific locale, then the
 * next more general and so on, finishing with the default locale.
 * The list will never contain the same locale twice.</p>
 *
 * @param locale  the locale to start from, null returns empty list
 * @param defaultLocale  the default locale to use if no other is found
 * @return the unmodifiable list of Locale objects, 0 being locale, not null
 */
public static List<Locale> localeLookupList(Locale locale, Locale defaultLocale) {
    List<Locale> list = new ArrayList<Locale>(4);
    if (locale != null) {
        list.add(locale);
        if (locale.getVariant().length() > 0) {
            list.add(new Locale(locale.getLanguage(), locale.getCountry()));
        }
        if (locale.getCountry().length() > 0) {
            list.add(new Locale(locale.getLanguage(), ""));
        }
        if (!list.contains(defaultLocale)) {
            list.add(defaultLocale);
        }
    }
    return Collections.unmodifiableList(list);
}

From source file:com.monarchapis.driver.exception.ConfigurationBundleApiErrorFactory.java

/**
 * Returns the array of strings based on the request locales.
 * // www .  j a  v a 2 s  .c om
 * @param request
 *            The API request
 * @return the array of variant strings
 */
private static String[] getLocaleArray(ApiRequest request) {
    Enumeration<Locale> locales = request.getLocales();
    ArrayList<String> localeList = new ArrayList<String>(5);

    while (locales.hasMoreElements()) {
        Locale locale = locales.nextElement();
        locale = new Locale(locale.getLanguage(), locale.getCountry());
        String lang = locale.getLanguage();

        if (StringUtils.isNotBlank(lang) && !"null".equals(lang)) {
            if (StringUtils.isNotBlank(locale.getCountry())) {
                localeList.add(locale.getLanguage() + '-' + locale.getCountry());
            }

            localeList.add(locale.getLanguage());
        }
    }

    return localeList.toArray(new String[localeList.size()]);
}

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

public static String getCustomerShippingState(Customer customer, Locale locale) {

    if (!StringUtils.isBlank(customer.getCustomerState())) {
        return customer.getCustomerState();
    }/*w w w . ja  v a 2s.  c o  m*/

    Map zones = RefCache.getAllZonesmap((LanguageUtil.getLanguageNumberCode(locale.getLanguage())));
    Zone zone = (Zone) zones.get(customer.getCustomerZoneId());
    if (zone != null) {
        return zone.getZoneName();
    }
    return "";
}

From source file:com.carlomicieli.jtrains.value.objects.LocalizedField.java

private static String keyFromLocale(Locale locale) {
    return locale.getLanguage();
}

From source file:com.joliciel.talismane.terminology.TalismaneTermExtractorMain.java

public static Map<TerminologyProperty, String> getDefaultTerminologyProperties(Locale locale) {
    Map<TerminologyProperty, String> terminologyProperties = new HashMap<TerminologyProperty, String>();
    if (locale.getLanguage().equals("fr")) {
        terminologyProperties.put(TerminologyProperty.adjectivalTags, "ADJ,VPP");
        terminologyProperties.put(TerminologyProperty.coordinationLabels, "coord,dep_coord");
        terminologyProperties.put(TerminologyProperty.determinentTags, "DET");
        terminologyProperties.put(TerminologyProperty.nominalTags, "NC,NPP");
        terminologyProperties.put(TerminologyProperty.nonStandaloneIfHasDependents, "VPR");
        terminologyProperties.put(TerminologyProperty.nonStandaloneTags, "P,CC,CS,PONCT,P+D");
        terminologyProperties.put(TerminologyProperty.nonTopLevelLabels, "det,coord,dep_coord");
        terminologyProperties.put(TerminologyProperty.prepositionalTags, "P,P+D");
        terminologyProperties.put(TerminologyProperty.termStopTags, "V,VS,VIMP,PRO,P+PRO,PROREL,PROWH,PONCT");
        terminologyProperties.put(TerminologyProperty.zeroDepthLabels, "prep,det,coord,dep_coord");
        terminologyProperties.put(TerminologyProperty.lemmaGender, "m");
        terminologyProperties.put(TerminologyProperty.lemmaNumber, "s");
    } else {/*  www .j a  v a2  s  .com*/
        throw new TalismaneException(
                "Terminology extraction properties unknown for language: " + locale.getLanguage());
    }
    return terminologyProperties;
}

From source file:com.google.android.mms.transaction.HttpUtils.java

private static void addLocaleToHttpAcceptLanguage(StringBuilder builder, Locale locale) {
    String language = locale.getLanguage();

    if (language != null) {
        builder.append(language);/*  ww w. ja  va 2s.  co m*/

        String country = locale.getCountry();

        if (country != null) {
            builder.append("-");
            builder.append(country);
        }
    }
}

From source file:com.trenako.entities.Review.java

private static String language(Locale locale) {
    if (locale == null) {
        return null;
    }/*from w  w  w. j av a  2 s  .  co  m*/

    return locale.getLanguage();
}

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

public static String getCustomerBillingState(Customer customer, Locale locale) {

    if (!StringUtils.isBlank(customer.getCustomerBillingState())) {
        return customer.getCustomerBillingState();
    }//ww w.  j a v a  2s . c om

    Map zones = RefCache.getAllZonesmap((LanguageUtil.getLanguageNumberCode(locale.getLanguage())));
    Zone zone = (Zone) zones.get(customer.getCustomerBillingZoneId());
    if (zone != null) {
        return zone.getZoneName();
    }
    return "";
}

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.
 *///  w w  w.  j a v a 2s  . c  o  m
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;
}