List of usage examples for java.util Locale Locale
public Locale(String language, String country)
From source file:Main.java
public static void setLocale(String lang, Resources res) { Locale myLocale;/* ww w .ja v a2 s. c o m*/ if (lang.equalsIgnoreCase("zh-rTW")) { myLocale = Locale.TRADITIONAL_CHINESE; } else if (lang.equalsIgnoreCase("zh-rCN") || lang.equalsIgnoreCase("zh")) { myLocale = Locale.SIMPLIFIED_CHINESE; } else if (lang.equalsIgnoreCase("pt-rBR") || lang.equalsIgnoreCase("pt")) { myLocale = new Locale("pt", "BR"); } else if (lang.equalsIgnoreCase("pt-rPT")) { myLocale = new Locale("pt", "PT"); } else { myLocale = new Locale(lang); } DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); }
From source file:Main.java
private static DateFormat getDateMonthHourMinuteDateFormat() { if (dateMonthHourMinuteDateFormat == null) { dateMonthHourMinuteDateFormat = new SimpleDateFormat("dd/MM' - 'HH:mm", new Locale("pt", "BR")); }/*w w w . j a v a 2 s .co m*/ return dateMonthHourMinuteDateFormat; }
From source file:Main.java
public static String getCurrentDateTime() { Date today = new Date(); Locale currentLocale = new Locale("KOREAN", "KOREA"); // String pattern = "yyyyMMddHHmmss"; String pattern = "yyyy-MM-dd HH:mm:ss"; // String pattern = "yyyy-MM-dd"; SimpleDateFormat formatter = new SimpleDateFormat(pattern, currentLocale); return formatter.format(today); }
From source file:Main.java
public static String capitalize(String input) { return input.toUpperCase(new Locale(Locale.ENGLISH.getLanguage(), Locale.US.getCountry())); }
From source file:Main.java
/** * Gets a locale for the given language code. *//*from www . j a va 2 s .com*/ public static Locale languageLocale(String languageCode) { if (TextUtils.isEmpty(languageCode)) return Locale.getDefault(); if (languageCode.length() > NO_REGION_LANG_CODE_LEN) { return new Locale(languageCode.substring(0, NO_REGION_LANG_CODE_LEN), languageCode.substring(REGION_SUBSTRING_INDEX)); } return new Locale(languageCode); }
From source file:Main.java
public static void setCountriesISOMap() { String[] isoCountryCodes = Locale.getISOCountries(); for (int i = 0; i < isoCountryCodes.length; i++) { Locale locale = new Locale("", isoCountryCodes[i]); countriesISOMap.put(locale.getDisplayCountry(), isoCountryCodes[i]); }//w w w .j ava2 s.com }
From source file:Main.java
private static Locale locale(String isoCode) { String[] codes = isoCode.split("_"); if (codes.length == 2) { return new Locale(codes[0].toLowerCase(), codes[1].toUpperCase()); } else if (codes.length == 1) { return new Locale(codes[0].toLowerCase()); }/*from www. j a va2 s .c o m*/ Log.e("WizardUtils", "Invalid locale " + isoCode); return null; }
From source file:Main.java
public static Locale toLocale(String str) { if (str == null) { return null; }//from ww w .ja v a2 s . c om int len = str.length(); if (len != 2 && len != 5 && len < 7) { throw new IllegalArgumentException("Invalid locale format: " + str); } char ch0 = str.charAt(0); char ch1 = str.charAt(1); if (ch0 < 'a' || ch0 > 'z' || ch1 < 'a' || ch1 > 'z') { throw new IllegalArgumentException("Invalid locale format: " + str); } if (len == 2) { return new Locale(str, ""); } else { if (str.charAt(2) != '_') { throw new IllegalArgumentException("Invalid locale format: " + str); } char ch3 = str.charAt(3); if (ch3 == '_') { return new Locale(str.substring(0, 2), "", str.substring(4)); } char ch4 = str.charAt(4); if (ch3 < 'A' || ch3 > 'Z' || ch4 < 'A' || ch4 > 'Z') { throw new IllegalArgumentException("Invalid locale format: " + str); } if (len == 5) { return new Locale(str.substring(0, 2), str.substring(3, 5)); } else { if (str.charAt(5) != '_') { throw new IllegalArgumentException("Invalid locale format: " + str); } return new Locale(str.substring(0, 2), str.substring(3, 5), str.substring(6)); } } }
From source file:Main.java
public static Locale toLocale(String languageCode) { String[] language = languageCode.split("-"); if (language.length > 1) { return new Locale(language[0], language[1]); }/*from w w w. j a va2 s . co m*/ return new Locale(language[0]); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); res.setHeader("Content-Language", "es"); Locale locale = new Locale("es", ""); DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); fmt.setTimeZone(TimeZone.getDefault()); out.println("En Espa\u00f1ol:"); out.println("\u00a1Hola Mundo!"); out.println(fmt.format(new Date())); }