List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:com.haulmont.cuba.core.entity.LocaleHelper.java
public static String getEnumLocalizedValue(String enumValue, String localeBundle) { if (enumValue == null) { return null; }//w ww .j av a 2 s .c o m if (localeBundle == null) { return enumValue; } Map<String, String> map = getLocalizedValuesMap(localeBundle); Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) { key += "_" + locale.getCountry(); } String result = map.getOrDefault(key + "/" + enumValue, ""); return Objects.equals(result, "") ? enumValue : result; }
From source file:de.innovationgate.wgpublisher.bi.BiBase.java
public static String getBrowserLanguageKey(javax.servlet.jsp.PageContext pageContext) { Enumeration enumLocales = pageContext.getRequest().getLocales(); Vector vecLocales = new Vector(); vecLocales.clear();//from w ww. ja va 2s. com String language = null; while (enumLocales.hasMoreElements()) vecLocales.add((Locale) enumLocales.nextElement()); for (int i = 0; i < vecLocales.size(); i++) { Locale currentLocale = (Locale) vecLocales.get(i); language = currentLocale.getLanguage().toUpperCase(); if (language.equalsIgnoreCase("DE") || language.equalsIgnoreCase("EN")) break; } if (language == null || language.equals("")) language = "EN"; return language; }
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Returns true, if <code>locale</code> is less specific than the system * default locale.//from ww w. jav a2 s . c o m * * @see Locale#getDefault() */ public static boolean matchesDefaultLocale(Locale locale) { Locale systemLocale = Locale.getDefault(); if (matchesOrIsMoreSpecific(systemLocale.getLanguage(), locale.getLanguage()) && matchesOrIsMoreSpecific(systemLocale.getCountry(), locale.getCountry()) && matchesOrIsMoreSpecific(systemLocale.getVariant(), locale.getVariant())) { return true; } return false; }
From source file:at.porscheinformatik.common.spring.web.extended.util.LocaleUtils.java
public static Locale closestSupportedLocale(List<Locale> supportedLocales, Locale locale) { if (locale == null || supportedLocales == null) { return null; }//w w w .java 2 s. c o m Locale closest = null; int closestMatches = 0; for (Locale l : supportedLocales) { int matches = 0; // If the language does not match no more processing is needed if (ObjectUtils.equals(l.getLanguage(), locale.getLanguage())) { matches++; // if the country does not match no more processing is needed if (ObjectUtils.equals(l.getCountry(), locale.getCountry())) { matches++; if (ObjectUtils.equals(l.getVariant(), locale.getVariant())) { matches++; } } } /* * If language, country and variant match, we have our locale and no * more iteration is needed */ if (matches == 3) { return l; } if (matches > closestMatches) { closestMatches = matches; closest = l; } } return closest; }
From source file:es.tunelator.Start.java
/** * Tests if the default locale has specific support *///w ww .ja v a 2 s.c om private static boolean isLocaleSupported() { Locale defaultLocale = Locale.getDefault(); String[] supportedLangs = Constants.SUPPORTED_LANGS; for (int i = 0; i < supportedLangs.length; i++) { if (defaultLocale.getLanguage().equals(new Locale(supportedLangs[i], "", "").getLanguage())) { return true; } } return false; }
From source file:com.limegroup.gnutella.gui.LanguageUtils.java
/** * Returns a score between -1 and 3 how well <code>specificLocale</code> * matches <code>genericLocale</code>. * /*from w ww. j a va2 s .c o m*/ * @return -1, if locales do not match, 3 if locales are equal */ public static int getMatchScore(Locale specificLocale, Locale genericLocale) { int i = 0; if (specificLocale.getLanguage().equals(genericLocale.getLanguage())) { i += 1; } else if (genericLocale.getLanguage().length() > 0) { return -1; } if (specificLocale.getCountry().equals(genericLocale.getCountry())) { i += 1; } else if (genericLocale.getCountry().length() > 0) { return -1; } if (specificLocale.getVariant().equals(genericLocale.getVariant())) { i += 1; } else if (genericLocale.getVariant().length() > 0) { return -1; } return i; }
From source file:com.haulmont.cuba.core.entity.LocaleHelper.java
public static String getLocalizedEnumeration(String enumerationValues, String localeBundle) { String result = null;/*from www . java 2 s. c o m*/ if (StringUtils.isNotEmpty(localeBundle)) { Properties localeProperties = loadProperties(localeBundle); if (localeProperties != null) { Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) { key += "_" + locale.getCountry(); } List<String> enumValues = new ArrayList<>(); String[] enumerationValuesArray = enumerationValues.split(","); Map<String, String> localizedValuesMap = LocaleHelper.getLocalizedValuesMap(localeBundle); for (String value : enumerationValuesArray) { String resultValue = localizedValuesMap.getOrDefault(key + "/" + value, value); enumValues.add(resultValue); } result = Joiner.on(",").join(enumValues); } } return result; }
From source file:com.aoindustries.website.clientarea.accounting.AddCreditCardAction.java
/** * Parses the first name in a locale-specific manner. *//* ww w . j a v a 2 s . com*/ public static String getFirstName(String name, Locale userLocale) { if (name == null) return null; name = name.trim(); if (userLocale.getLanguage().equals(Locale.JAPANESE.getLanguage())) { // Last then first int pos = name.lastIndexOf(' '); if (pos == -1) return ""; else return name.substring(pos + 1).trim(); } else { // First then last int pos = name.indexOf(' '); if (pos == -1) return ""; else return name.substring(0, pos).trim(); } }
From source file:com.aoindustries.website.clientarea.accounting.AddCreditCardAction.java
/** * Parses the last name in a locale-specific manner. *///w ww . ja v a 2 s .c o m public static String getLastName(String name, Locale userLocale) { if (name == null) return null; name = name.trim(); if (userLocale.getLanguage().equals(Locale.JAPANESE.getLanguage())) { // Last then first int pos = name.lastIndexOf(' '); if (pos == -1) return name; else return name.substring(0, pos).trim(); } else { // First then last int pos = name.indexOf(' '); if (pos == -1) return name; else return name.substring(pos + 1).trim(); } }
From source file:Main.java
public static String getLocaleLanguage(Context context) { Locale locale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { locale = context.getResources().getConfiguration().getLocales().get(0); } else {//from www . ja v a 2s . co m locale = context.getResources().getConfiguration().locale; } return locale.getLanguage(); }