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: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  w  ww  . j ava2  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:com.omnigon.aem.common.utils.LocaleUtils.java

public static String getLanguageCountryCode(Locale locale) {
    if (locale != null) {
        StringBuilder b = new StringBuilder();

        if (StringUtils.isNotBlank(locale.getLanguage())) {
            b.append(locale.getLanguage().toLowerCase());
        }// www  .j ava 2s .c om

        if (StringUtils.isNotBlank(locale.getCountry())) {
            b.append("_");
            b.append(locale.getCountry().toLowerCase());
        }

        return b.toString();
    } else {
        return StringUtils.EMPTY;
    }
}

From source file:dk.statsbiblioteket.util.i18n.BundleCache.java

private static String getLocaleBundleName(String bundleName, Locale locale) {
    return bundleName + "_" + locale.getLanguage() + ".properties";
}

From source file:net.sf.zekr.engine.search.SearchUtils.java

/**
 * Simplifies sura name text to be used in a suggestion list.
 * //from  w w w  .java  2 s  . c  o m
 * @param text original text
 * @return simplified text
 */
public static String simplifySuranameText(String text) {
    ApplicationConfig conf = ApplicationConfig.getInstance();
    SearchInfo searchInfo = conf.getSearchInfo();
    Locale locale = QuranPropertiesUtils.getSuraNameModeLocale();
    String langCode = locale.getLanguage();
    text = text.toLowerCase(locale);
    Map<Pattern, String> rep = new LinkedHashMap<Pattern, String>(searchInfo.getDefaultReplacePattern());
    if (searchInfo.containsLanguageReplacePattern(langCode)) {
        rep.putAll(searchInfo.getReplacePattern(langCode));
    }
    Pattern punct = searchInfo.getPunctuation(langCode);
    if (punct != null) {
        rep.put(punct, "");
    }
    text = RegexUtils.replaceAll(rep, text);
    return text;
}

From source file:eu.europeana.core.util.web.ControllerUtil.java

public static Language getLocale(HttpServletRequest request) {
    LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
    Locale locale = localeResolver.resolveLocale(request);
    String currentLangCode = locale.getLanguage();
    return Language.findByCode(currentLangCode);
}

From source file:be.fedict.eid.tsl.TrustServiceListUtils.java

/**
 * Sets the value according to the given locale.
 * //w ww .  ja  v  a2  s.co m
 * @param value
 * @param locale
 * @param i18nName
 */
public static void setValue(String value, Locale locale, InternationalNamesType i18nName) {
    LOG.debug("set value for locale: " + locale.getLanguage());
    List<MultiLangNormStringType> names = i18nName.getName();
    /*
     * First try to locate an existing entry for the given locale.
     */
    MultiLangNormStringType localeName = null;
    for (MultiLangNormStringType name : names) {
        String lang = name.getLang().toLowerCase();
        if (locale.getLanguage().equals(lang)) {
            localeName = name;
            break;
        }
    }
    if (null == localeName) {
        /*
         * If none was found, create a new one.
         */
        ObjectFactory objectFactory = new ObjectFactory();
        localeName = objectFactory.createMultiLangNormStringType();
        localeName.setLang(locale.getLanguage());
        names.add(localeName);
    }
    localeName.setValue(value);
}

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

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

    Map countries = RefCache.getAllcountriesmap(((LanguageUtil.getLanguageNumberCode(locale.getLanguage()))));
    Country country = (Country) countries.get(customer.getCustomerBillingCountryId());
    if (country != null) {
        return country.getCountryName();
    }//from w  w  w  . jav  a 2 s . c  om
    return "";
}

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

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

    Map countries = RefCache.getAllcountriesmap(((LanguageUtil.getLanguageNumberCode(locale.getLanguage()))));
    Country country = (Country) countries.get(customer.getCustomerCountryId());
    if (country != null) {
        return country.getCountryName();
    }/*w  w  w  .  j a  va 2s. c om*/
    return "";
}

From source file:fr.gouv.culture.thesaurus.util.LangUtils.java

/**
 * Renvoie le tableau des langues associe aux locales spcifies.
 * //  w  w w .j  a va  2s. c  om
 * @param locales
 *            Locales dont il faut rcuprer les langues
 * @return Langues
 */
public static String[] convertLocalesToLanguages(@SuppressWarnings("rawtypes") final List locales) {
    final String[] languages = new String[locales.size()];
    for (int localeId = 0; localeId < languages.length; localeId++) {
        final Locale locale = (Locale) locales.get(localeId);
        languages[localeId] = locale == null ? null : locale.getLanguage();
    }
    return languages;
}

From source file:nu.yona.server.Translator.java

private static Object determineLocaleInfix() {
    Locale locale = LocaleContextHolder.getLocale();
    if (locale.equals(EN_US_LOCALE)) {
        return "";
    }//w  w  w.  jav a  2 s  .  c om
    return "_" + locale.getLanguage();
}