List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:Main.java
public static String toLanguageTag(Locale locale) { StringBuilder languageTag = new StringBuilder(); languageTag.append(locale.getLanguage()); if (!isNullOrEmpty(locale.getCountry())) { languageTag.append('-').append(locale.getCountry()); }/*from ww w . j a v a 2s . c om*/ if (!isNullOrEmpty(locale.getVariant())) { languageTag.append('-').append(locale.getVariant()); } return languageTag.toString(); }
From source file:Main.java
private static String i(Context context) { if (h == null) { String s = (new WebView(context)).getSettings().getUserAgentString(); if (s == null || s.length() == 0 || s.equals("Java0")) { String s1 = System.getProperty("os.name", "Linux"); String s2 = (new StringBuilder()).append("Android ").append(android.os.Build.VERSION.RELEASE) .toString();//from ww w. j a v a 2s . co m Locale locale = Locale.getDefault(); String s3 = locale.getLanguage().toLowerCase(); if (s3.length() == 0) s3 = "en"; String s4 = locale.getCountry().toLowerCase(); String s5; String s6; if (s4.length() > 0) s5 = (new StringBuilder()).append(s3).append("-").append(s4).toString(); else s5 = s3; s6 = (new StringBuilder()).append(Build.MODEL).append(" Build/").append(Build.ID).toString(); s = (new StringBuilder()).append("Mozilla/5.0 (").append(s1).append("; U; ").append(s2).append("; ") .append(s5).append("; ").append(s6).append(") AppleWebKit/0.0 (KHTML, like ") .append("Gecko) Version/0.0 Mobile Safari/0.0").toString(); } h = (new StringBuilder()).append(s).append(" (Mobile; ").append("afma-sdk-a-v").append("4.1.0") .append(")").toString(); } return h; }
From source file:Main.java
/** * Determine the RFC 3066 compliant language tag, * as used for the HTTP "Accept-Language" header. * @param locale the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as String *///from w ww . j ava 2 s.co m public static String toLanguageTag(Locale locale) { return locale.getLanguage() + (hasText(locale.getCountry()) ? "-" + locale.getCountry() : ""); }
From source file:Main.java
/** * //from w w w . j a va 2 s. c om * Returns the "parent" locale of a given locale. * * * If the original locale is only language-based, the {@link #NULL_LOCALE} * object is returned. * * * If the original locale is {@link #NULL_LOCALE}, then <code>null</code> * is returned. * * * @param locale The original locale. * @return The parent locale. */ public static Locale getParentLocale(Locale locale) { Locale retValue = null; String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (!"".equals(variant)) { retValue = new Locale(language, country); } else if (!"".equals(country)) { retValue = new Locale(language); } else if (!"".equals(language)) { retValue = NULL_LOCALE; } return retValue; }
From source file:com.aestheticsw.jobkeywords.service.termextractor.support.SearchUtils.java
public static Locale lookupLocaleByCountry(String country) { List<Locale> localeList = LocaleUtils.languagesByCountry(country); if (localeList == null || localeList.size() == 0) { throw new IllegalArgumentException("Invalid country code: " + country); }/*from w w w. j a va2s.c o m*/ Locale locale = localeList.get(0); // if English isn't the language of the first Locale, then try to find English. if (!locale.getLanguage().equals("en")) { for (Locale option : localeList) { if (option.getLanguage().equals("en")) { return option; } } } return locale; }
From source file:org.sacredscripturefoundation.commons.locale.LocaleStringUtils.java
/** * Determine the RFC 3066 compliant language tag, as used for the HTTP * "Accept-Language" header./*from w w w .ja v a 2 s. c o m*/ * * @param locale the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as String */ public static String toLanguageTag(Locale locale) { StringBuilder sb = new StringBuilder(locale.getLanguage()); if (!locale.getCountry().isEmpty()) { sb.append("-"); sb.append(locale.getCountry()); } return sb.toString(); }
From source file:ru.mystamps.web.util.LocaleUtils.java
public static String getLanguageOrDefault(Locale locale, String defaultValue) { if (locale == null) { return defaultValue; }/*from w w w.j av a 2s . c om*/ return locale.getLanguage(); }
From source file:Main.java
/** * Generate a User-Agent used in HTTP request to pick an ad. * Source used from Android source code "frameworks/base/core/java/android/webkit/WebSettings.java" * /*from w w w.j a v a2 s. c o m*/ * @return */ protected static String getUA() { if (UA != null) return UA; StringBuffer arg = new StringBuffer(); final String version = Build.VERSION.RELEASE; if (version.length() > 0) { arg.append(version); } else { arg.append("1.0"); } arg.append("; "); final Locale l = Locale.getDefault(); final String language = l.getLanguage(); if (language != null) { arg.append(language.toLowerCase()); final String country = l.getCountry(); if (country != null) { arg.append("-"); arg.append(country.toLowerCase()); } } else { arg.append("de"); } final String model = Build.MODEL; if (model.length() > 0) { arg.append("; "); arg.append(model); } final String id = Build.ID; if (id.length() > 0) { arg.append(" Build/"); arg.append(id); } // TODO: add version detection for AppleWebKit, Version and Safari final String rawUA = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2"; UA = String.format(rawUA, arg); return UA; }
From source file:Main.java
/** * Generate a User-Agent used in HTTP request to pick an ad. Source used * from Android source code//from ww w .j a v a2s .c o m * "frameworks/base/core/java/android/webkit/WebSettings.java" * * @return */ public static String getUA() { if (sUA != null) return sUA; StringBuffer arg = new StringBuffer(); final String version = Build.VERSION.RELEASE; if (version.length() > 0) { arg.append(version); } else { arg.append("1.0"); } arg.append("; "); final Locale l = Locale.getDefault(); final String language = l.getLanguage(); if (language != null) { arg.append(language.toLowerCase()); final String country = l.getCountry(); if (country != null) { arg.append("-"); arg.append(country.toLowerCase()); } } else { arg.append("de"); } final String model = Build.MODEL; if (model.length() > 0) { arg.append("; "); arg.append(model); } final String id = Build.ID; if (id.length() > 0) { arg.append(" Build/"); arg.append(id); } // TODO: add version detection for AppleWebKit, Version and Safari final String rawUA = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2"; sUA = String.format(rawUA, arg); return sUA; }
From source file:com.sonicle.webtop.core.app.servlet.ServletHelper.java
public static Locale homogenizeLocale(HttpServletRequest request) { Locale locale = request.getLocale(); if (locale.getLanguage().equals("it")) { return new Locale("it", "IT"); } else {/*from ww w . ja v a 2s .com*/ return new Locale("en", "EN"); } }