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:com.code4bones.utils.HttpUtils.java

private static void addLocaleToHttpAcceptLanguage(StringBuilder builder, Locale locale) {
    String language = convertObsoleteLanguageCodeToNew(locale.getLanguage());
    if (language != null) {
        builder.append(language);/*from   w ww  .  j a v  a 2  s.  co  m*/
        String country = locale.getCountry();
        if (country != null) {
            builder.append("-");
            builder.append(country);
        }
    }
}

From source file:com.adjust.sdk.Util.java

private static String getLanguage(final Locale locale) {
    final String language = locale.getLanguage();
    return sanitizeStringShort(language);
}

From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java

private static boolean isLocaleSupported(Locale locale) {

    String defaultLocal = SingletonConfig.getInstance().getConfigValue("SPAGOBI.LANGUAGE_SUPPORTED.LANGUAGES");
    String tmp = "[" + locale.getLanguage() + "," + locale.getCountry() + "]";
    logger.debug("Check if " + tmp + " is supported");
    return defaultLocal.contains(tmp);
}

From source file:com.p5solutions.core.utils.Comparison.java

/**
 * Checks if is french.//  ww  w.  ja  v  a2  s  . com
 * 
 * @param locale
 *          the locale
 * @return true, if is french
 */
public static boolean isFrench(Locale locale) {
    String lang = Locale.FRENCH.getLanguage();
    if (lang.equals(locale.getLanguage())) {
        return true;
    }
    return false;
}

From source file:com.p5solutions.core.utils.Comparison.java

/**
 * Checks if is english.//from   www.  j a  va2 s .  c o m
 * 
 * @param locale
 *          the locale
 * @return true, if is english
 */
public static boolean isEnglish(Locale locale) {
    String lang = Locale.ENGLISH.getLanguage();
    if (lang.equals(locale.getLanguage())) {
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * Calculate the postfixes along the search path from the base bundle to the
 * bundle specified by baseName and locale. Method copied from
 * java.util.ResourceBundle//ww w  .j a  v a  2s.c  om
 *
 * @param locale The locale.
 * @return a list of postfixes to add to filenames.
 * @since 2.1.0
 */
public static List<String> calculatePostfixes(Locale locale) {
    final List<String> result = new ArrayList<String>();
    // The default configuration file must be loaded to allow correct
    // definition inheritance.
    result.add("");

    if (locale == null) {
        return result;
    }

    final String language = locale.getLanguage();
    final int languageLength = language.length();
    final String country = locale.getCountry();
    final int countryLength = country.length();
    final String variant = locale.getVariant();
    final int variantLength = variant.length();

    if (languageLength + countryLength + variantLength == 0) {
        // The locale is "", "", "".
        return result;
    }

    final StringBuffer temp = new StringBuffer();
    temp.append('_');
    temp.append(language);

    if (languageLength > 0) {
        result.add(temp.toString());
    }

    if (countryLength + variantLength == 0) {
        return result;
    }

    temp.append('_');
    temp.append(country);

    if (countryLength > 0) {
        result.add(temp.toString());
    }

    if (variantLength == 0) {
        return result;
    } else {
        temp.append('_');
        temp.append(variant);
        result.add(temp.toString());
        return result;
    }
}

From source file:com.norconex.commons.lang.time.DurationUtil.java

private static String getString(Locale locale, long unitValue, final String key, boolean islong) {
    String k = key;//from w w  w. j  av  a  2 s  . co  m
    if (islong && unitValue > 1) {
        k += "s";
    }
    String pkg = ClassUtils.getPackageName(DurationUtil.class);
    ResourceBundle time;
    if (locale != null && Locale.FRENCH.getLanguage().equals(locale.getLanguage())) {
        time = ResourceBundle.getBundle(pkg + ".time", Locale.FRENCH);
    } else {
        time = ResourceBundle.getBundle(pkg + ".time");
    }
    if (islong) {
        return " " + unitValue + " " + time.getString("timeunit.long." + k);
    }
    return unitValue + time.getString("timeunit.short." + k);
}

From source file:com.android.mms.service.HttpUtils.java

private static void addLocaleToHttpAcceptLanguage(StringBuilder builder, Locale locale) {
    final String language = convertObsoleteLanguageCodeToNew(locale.getLanguage());
    if (language != null) {
        builder.append(language);/*from  w w  w.  j  ava2  s . com*/
        final String country = locale.getCountry();
        if (country != null) {
            builder.append("-");
            builder.append(country);
        }
    }
}

From source file:net.sf.eclipsecs.core.builder.CheckerFactory.java

/**
 * Creates a new checker and configures it with the given configuration file.
 *
 * @param input//  w  ww. j  a va2s .  c o m
 *            the input source for the configuration file
 * @param configFileUri
 *            the URI of the configuration file, or <code>null</code> if it could not be determined
 * @param propResolver
 *            a property resolver null
 * @param project
 *            the project
 * @return the newly created Checker
 * @throws CheckstyleException
 *             an exception during the creation of the checker occured
 */
private static Checker createCheckerInternal(InputSource input, PropertyResolver propResolver, IProject project)
        throws CheckstyleException, CheckstylePluginException {

    // load configuration
    Configuration configuration = ConfigurationLoader.loadConfiguration(input, propResolver, true);

    // create and configure checker
    Checker checker = new Checker();
    checker.setModuleClassLoader(CheckstylePlugin.getDefault().getAddonExtensionClassLoader());
    try {
        checker.setCharset(project.getDefaultCharset());
    } catch (UnsupportedEncodingException e) {
        CheckstylePluginException.rethrow(e);
    } catch (CoreException e) {
        CheckstylePluginException.rethrow(e);
    }

    // set the eclipse platform locale
    Locale platformLocale = CheckstylePlugin.getPlatformLocale();
    checker.setLocaleLanguage(platformLocale.getLanguage());
    checker.setLocaleCountry(platformLocale.getCountry());
    checker.setClassloader(sSharedClassLoader);

    checker.configure(configuration);

    // reset the basedir if it is set so it won't get into the plugins way
    // of determining workspace resources from checkstyle reported file
    // names, see
    // https://sourceforge.net/tracker/?func=detail&aid=2880044&group_id=80344&atid=559497
    if (checker.getBasedir() != null) {
        checker.setBasedir(null);
    }

    return checker;
}

From source file:marytts.features.FeatureRegistry.java

/**
 * Get the feature processor manager associated with the given locale, if any.
 * @param locale// ww w.j  a  v a 2s . c  om
 * @return the feature processor manager, or null if there is no locale-specific
 * feature processor manager.
 */
public static FeatureProcessorManager getFeatureProcessorManager(Locale locale) {
    FeatureProcessorManager m = managersByLocale.get(locale);
    if (m != null)
        return m;
    // Maybe locale is language_COUNTRY, so look up by language also:
    Locale lang = new Locale(locale.getLanguage());
    return managersByLocale.get(lang);
}