List of usage examples for java.util Locale Locale
public Locale(String language)
From source file:kaleidoscope.util.HttpUtils.java
public static Locale getLocale(String acceptLanguage) { Locale locale = null;/* w ww .ja v a 2 s. c o m*/ if (StringUtils.isEmpty(acceptLanguage) != true) { StringTokenizer langToken = new StringTokenizer(acceptLanguage, ",; "); String language = langToken.nextToken().replace('-', '_'); StringTokenizer localeToken = new StringTokenizer(language, "_"); switch (localeToken.countTokens()) { case 1: locale = new Locale(localeToken.nextToken()); break; case 2: locale = new Locale(localeToken.nextToken(), localeToken.nextToken()); break; case 3: locale = new Locale(localeToken.nextToken(), localeToken.nextToken(), localeToken.nextToken()); break; } } if (locale == null) { locale = Locale.getDefault(); } return locale; }
From source file:Main.java
public static void setLocale(Context ctx, String lang) { Locale locale;/* w w w.java 2s. com*/ /* if(lang.equals("zh") || lang.equals("zh-HK") || lang.equals("zh-")) locale = Locale.TRADITIONAL_CHINESE; else if(lang.equals("zh-CN")) locale = Locale.SIMPLIFIED_CHINESE; else locale = new Locale(lang);*/ locale = new Locale(lang); Resources res = ctx.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = locale; res.updateConfiguration(conf, dm); }
From source file:Main.java
/** * Creates a locale from a string specification. *///from w w w .j ava 2 s . com public static Locale constructLocaleFromString(final String localeStr) { if (localeStr == null) return null; synchronized (sLocaleCache) { if (sLocaleCache.containsKey(localeStr)) return sLocaleCache.get(localeStr); Locale retval = null; String[] localeParams = localeStr.split("_", 3); if (localeParams.length == 1) { retval = new Locale(localeParams[0]); } else if (localeParams.length == 2) { retval = new Locale(localeParams[0], localeParams[1]); } else if (localeParams.length == 3) { retval = new Locale(localeParams[0], localeParams[1], localeParams[2]); } if (retval != null) { sLocaleCache.put(localeStr, retval); } return retval; } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static Locale getLocaleForLanguageTag(@Nullable String locale) { Locale parsedLocale = Locale.getDefault(); if (!TextUtils.isEmpty(locale)) { try {/*from w ww . j a v a2 s . com*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { parsedLocale = Locale.forLanguageTag(locale); } else { parsedLocale = new Locale(locale); } } catch (Exception e) { Log.d(TAG, "Failed to parse locale " + locale + ". Defaulting to " + parsedLocale); } } return parsedLocale; }
From source file:br.ufg.calendario.components.LocaleBean.java
public static String getMessage(String msg) { ResourceBundle messages = ResourceBundle.getBundle("br.ufg.calendario.locale.messages", new Locale(getInstance().getLocale())); return messages.getString(msg); }
From source file:com.ijuru.kwibuka.WordListWordifierTest.java
@BeforeClass public static void setup() throws IOException { InputStreamReader reader = new InputStreamReader( WordListWordifierTest.class.getClassLoader().getResourceAsStream("words.lst")); wordifier = WordListWordifier.fromWordlist(new Locale("en"), reader); }
From source file:DateTimeUtil.java
/** * Return a String value of Now() in a specify format * @param lang lingua di default//from w w w . ja v a 2s. co m * @param format formato della data vedi esempi tsDefaultFormats * @return String value of Now() in a specify format */ public static final String getNowWithFormat(String format, String lang) { Calendar cal = Calendar.getInstance(TimeZone.getDefault()); String DATE_FORMAT = format; SimpleDateFormat sdf = null; if (lang != null) { sdf = new SimpleDateFormat(DATE_FORMAT, new Locale(lang)); } else { sdf = new SimpleDateFormat(DATE_FORMAT); } sdf.setTimeZone(TimeZone.getDefault()); return sdf.format(cal.getTime()); }
From source file:Main.java
/** * Parses a comma separated list of engine locale preferences. The list is * of the form {@code "engine_name_1:locale_1,engine_name_2:locale2"} and so * on and so forth. Returns null if the list is empty, malformed or if there * is no engine specific preference in the list. *//* ww w .j a v a2 s . co m*/ private static Locale parseEngineLocalePrefFromList(String prefValue, String engineName) { if (TextUtils.isEmpty(prefValue)) { return null; } final String[] prefValues = prefValue.split(","); for (String value : prefValues) { final int delimiter = value.indexOf(':'); if (delimiter > 0) { if (engineName.equals(value.substring(0, delimiter))) { return new Locale(value.substring(delimiter + 1)); } } } return null; }
From source file:Main.java
/** * Parses a string into a locale. The string is expected to be of the same * format of the string obtained by calling Locale.toString(). * /* w w w .j av a2 s.com*/ * @param localeString * string representation of a locale * @return a locale or <code>null</code> if string is empty or null */ public static Locale parseLocale(String localeString) { if (localeString == null || localeString.trim().length() == 0) { return null; } StringTokenizer tokens = new StringTokenizer(localeString, "_"); //$NON-NLS-1$ List<String> localeSections = new ArrayList<String>(); while (tokens.hasMoreTokens()) { localeSections.add(tokens.nextToken()); } Locale locale = null; switch (localeSections.size()) { case 1: locale = new Locale(localeSections.get(0)); break; case 2: locale = new Locale(localeSections.get(0), localeSections.get(1)); break; case 3: locale = new Locale(localeSections.get(0), localeSections.get(1), localeSections.get(2)); break; default: break; } return locale; }
From source file:de.jlo.talendcomp.json.TypeUtil.java
public static DecimalFormat getNumberFormat(String localeStr) { DecimalFormat nf = numberformatMap.get(localeStr); if (nf == null) { Locale locale = new Locale(localeStr); nf = (DecimalFormat) NumberFormat.getInstance(locale); numberformatMap.put(localeStr, nf); }/*from w ww. j av a 2s. c om*/ return nf; }