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 getLocalizedName(String localeBundle) { Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String localeName = null;/*from w w w .j ava2s . c om*/ if (StringUtils.isNotEmpty(localeBundle)) { Properties localeProperties = loadProperties(localeBundle); if (localeProperties != null) { String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) key += "_" + locale.getCountry(); if (localeProperties.containsKey(key)) localeName = (String) localeProperties.get(key); } } return localeName; }
From source file:com.astamuse.asta4d.util.i18n.LocalizeUtil.java
public static String[] getCandidatePaths(String path, Locale locale) { int dotIndex = path.lastIndexOf("."); String name = dotIndex > 0 ? path.substring(0, dotIndex) : path; String extension = dotIndex > 0 ? path.substring(dotIndex) : StringUtils.EMPTY; List<String> candidatePathList = new ArrayList<>(); if (!StringUtils.isEmpty(locale.getVariant())) { candidatePathList.add(name + '_' + locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant() + extension); }/* www . ja v a 2 s . c o m*/ if (!StringUtils.isEmpty(locale.getCountry())) { candidatePathList.add(name + '_' + locale.getLanguage() + "_" + locale.getCountry() + extension); } if (!StringUtils.isEmpty(locale.getLanguage())) { candidatePathList.add(name + '_' + locale.getLanguage() + extension); } candidatePathList.add(path); return candidatePathList.toArray(new String[candidatePathList.size()]); }
From source file:Main.java
/** * @param context// w w w. j a v a 2 s .c o m * if null, use the default format (Mozilla/5.0 (Linux; U; * Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 * %sSafari/534.30). * @return */ public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class<?> sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase()); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase()); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:marytts.features.FeatureRegistry.java
/** * For the given locale, return the best feature manager. That is either * the locale-specific feature manager, if any, * or the language-specific feature manager, if any, or the fallback feature manager. * @param locale//from ww w. j av a2s. co m * @return a feature processor manager object. If this returns null, something is broken. */ public static FeatureProcessorManager determineBestFeatureProcessorManager(Locale locale) { FeatureProcessorManager mgr = getFeatureProcessorManager(locale); // Locale can have been en_US etc, i.e. language + country; let's try // language only as well. if (mgr == null) { Locale lang = new Locale(locale.getLanguage()); mgr = getFeatureProcessorManager(lang); } if (mgr == null) { mgr = getFallbackFeatureProcessorManager(); } assert mgr != null; return mgr; }
From source file:com.heliosphere.demeter.base.resource.bundle.ResourceBundleManager.java
/** * Sets the language used by the {@link ResourceBundleManager}. * <p>//from w w w.j a va 2s . c o m * <b>Note:</b> Calling this service forces the * {@link ResourceBundleManager} to reload all the resource bundle files * according to the new locale. * <p> * @param locale {@link Locale} corresponding to the new language to set. */ @Synchronized public static final void setLocale(final Locale locale) { if (locale.getLanguage() != ResourceBundleManager.locale.getLanguage()) { refresh(locale); } }
From source file:be.fedict.eid.tsl.TrustServiceListUtils.java
/** * Gives back the value according to the given locale. * //from w w w . ja v a 2 s . co m * @param i18nName * @param locale * @return */ static String getValue(InternationalNamesType i18nName, Locale locale) { if (null == i18nName) { return null; } List<MultiLangNormStringType> names = i18nName.getName(); String enValue = null; for (MultiLangNormStringType name : names) { String lang = name.getLang().toLowerCase(); if ("en".equals(lang)) { enValue = name.getValue(); } if (locale.getLanguage().equals(lang)) { return name.getValue(); } } if (null != enValue) { return enValue; } return names.get(0).getValue(); }
From source file:com.heliosphere.athena.base.resource.bundle.ResourceBundleManager.java
/** * Sets the language used by the {@link ResourceBundleManager}. * <p>/*from w w w .j a va2 s .c o m*/ * <b>Note:</b> Calling this service forces the * {@link ResourceBundleManager} to reload all the resource bundle files * according to the new locale. * <p> * @param locale {@link Locale} corresponding to the new language to set. */ @Synchronized public static final void setLocale(final Locale locale) { if (!locale.getLanguage().equals(ResourceBundleManager.locale.getLanguage())) { refresh(locale); } }
From source file:Main.java
/** * @param context if null, use the default format * (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30). * @return/* www .ja v a 2 s. c om*/ */ public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase()); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase()); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:LocaleUtils.java
/** * <p>Obtains the list of locales to search through when performing * a locale search.</p>/*from www .j a va 2 s.co 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, never null */ public static List localeLookupList(Locale locale, Locale defaultLocale) { List list = new ArrayList(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) == false) { list.add(defaultLocale); } } return Collections.unmodifiableList(list); }
From source file:com.googlecode.psiprobe.Utils.java
public static List getNamesForLocale(String baseName, Locale locale) { List result = new ArrayList(3); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuffer temp = new StringBuffer(baseName); if (language.length() > 0) { temp.append('_').append(language); result.add(0, temp.toString());/* ww w . j a va2s . c om*/ } if (country.length() > 0) { temp.append('_').append(country); result.add(0, temp.toString()); } if (variant.length() > 0) { temp.append('_').append(variant); result.add(0, temp.toString()); } return result; }