/** @param args */ public static void main(String[] args) { Double doubleValue = Double.valueOf(123456789.555D); Locale locale = Locale.getDefault(); Currency currency = Currency.getInstance(locale); NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale); System.out.println("locale:" + locale.getDisplayName()); System.out.println("Currency:" + currency.getDisplayName()); System.out.println(numberFormat.format(doubleValue)); System.out.println( "Locale.FRANCE:" + NumberFormat.getCurrencyInstance(Locale.FRANCE).format(doubleValue)); }
/* * @bug 4147552 4778440 */ public void Test4147552() { Locale[] locales = { new Locale("no", "NO"), new Locale("no", "NO", "B"), new Locale("no", "NO", "NY") }; String[] englishDisplayNames = { "Norwegian (Norway)", "Norwegian (Norway,Bokm\u00e5l)", "Norwegian (Norway,Nynorsk)" }; String[] norwegianDisplayNames = { "norsk (Norge)", "norsk (Norge,bokm\u00e5l)", "norsk (Norge,nynorsk)" }; for (int i = 0; i < locales.length; i++) { Locale loc = locales[i]; if (!loc.getDisplayName(Locale.US).equals(englishDisplayNames[i])) errln( "English display-name mismatch: expected " + englishDisplayNames[i] + ", got " + loc.getDisplayName()); if (!loc.getDisplayName(loc).equals(norwegianDisplayNames[i])) errln( "Norwegian display-name mismatch: expected " + norwegianDisplayNames[i] + ", got " + loc.getDisplayName(loc)); } }
private void doTestDisplayNames(Locale inLocale, int compareIndex, boolean defaultIsFrench) { if (defaultIsFrench && !Locale.getDefault().getLanguage().equals("fr")) errln( "Default locale should be French, but it's really " + Locale.getDefault().getLanguage()); else if (!defaultIsFrench && !Locale.getDefault().getLanguage().equals("en")) errln( "Default locale should be English, but it's really " + Locale.getDefault().getLanguage()); for (int i = 0; i <= MAX_LOCALES; i++) { Locale testLocale = new Locale(dataTable[LANG][i], dataTable[CTRY][i], dataTable[VAR][i]); logln(" Testing " + testLocale + "..."); String testLang; String testCtry; String testVar; String testName; if (inLocale == null) { testLang = testLocale.getDisplayLanguage(); testCtry = testLocale.getDisplayCountry(); testVar = testLocale.getDisplayVariant(); testName = testLocale.getDisplayName(); } else { testLang = testLocale.getDisplayLanguage(inLocale); testCtry = testLocale.getDisplayCountry(inLocale); testVar = testLocale.getDisplayVariant(inLocale); testName = testLocale.getDisplayName(inLocale); } String expectedLang; String expectedCtry; String expectedVar; String expectedName; expectedLang = dataTable[compareIndex][i]; if (expectedLang.equals("") && defaultIsFrench) expectedLang = dataTable[DLANG_EN][i]; if (expectedLang.equals("")) expectedLang = dataTable[DLANG_ROOT][i]; expectedCtry = dataTable[compareIndex + 1][i]; if (expectedCtry.equals("") && defaultIsFrench) expectedCtry = dataTable[DCTRY_EN][i]; if (expectedCtry.equals("")) expectedCtry = dataTable[DCTRY_ROOT][i]; expectedVar = dataTable[compareIndex + 2][i]; if (expectedVar.equals("") && defaultIsFrench) expectedVar = dataTable[DVAR_EN][i]; if (expectedVar.equals("")) expectedVar = dataTable[DVAR_ROOT][i]; expectedName = dataTable[compareIndex + 3][i]; if (expectedName.equals("") && defaultIsFrench) expectedName = dataTable[DNAME_EN][i]; if (expectedName.equals("")) expectedName = dataTable[DNAME_ROOT][i]; if (!testLang.equals(expectedLang)) errln("Display language mismatch: " + testLang + " versus " + expectedLang); if (!testCtry.equals(expectedCtry)) errln("Display country mismatch: " + testCtry + " versus " + expectedCtry); if (!testVar.equals(expectedVar)) errln("Display variant mismatch: " + testVar + " versus " + expectedVar); if (!testName.equals(expectedName)) errln("Display name mismatch: " + testName + " versus " + expectedName); } }
public static String getLocaleName(Locale loc, boolean isDefault) { String value; if (!isDefault) { value = loc.getDisplayName(JPRManagerLauncher.getLocale()); } else { if (loc == null) loc = Util.parseLocale(JPRManagerLauncher.getAppConf().getDefaultLanguage()); value = JPRManagerLauncher.getResourceData().getText("main.tc.values") + " [" + loc.getDisplayName(JPRManagerLauncher.getLocale()) + "]"; } return value; }
public List<Locale> getAvailableLanguages() { Locale[] locales = Locale.getAvailableLocales(); Map<String, Locale> localeMap = new HashMap<String, Locale>(); // remove all variants for (Locale locale : locales) { if (isTranslationsOnly() && !ArrayUtils.contains(config.getAvailableTranslations(), locale.getLanguage())) { continue; } if (localeMap.containsKey(locale.getLanguage()) && locale.getDisplayName().indexOf('(') != -1) { continue; } localeMap.put(locale.getLanguage(), locale); } SortedSet<Locale> localeSet = new TreeSet<Locale>(new LocaleComparator(LocaleComparator.CompareType.LANGUAGE)); for (Locale locale : localeMap.values()) { localeSet.add(locale); } return new ArrayList<Locale>(localeSet); }
@RequestMapping(value = "/", method = RequestMethod.GET) public String main(@ModelAttribute User user, HttpSession session, Locale locale) { logger.info(locale.getDisplayLanguage()); logger.info( messageSource.getMessage("locale", new String[] {locale.getDisplayName(locale)}, locale)); return "login"; }
private void initializeLanguageDialog() { TreeMap<String, String> items = new TreeMap<String, String>(); for (String localeCode : mAppLanguages) { Locale loc; if (localeCode.length() > 2) { loc = new Locale(localeCode.substring(0, 2), localeCode.substring(3, 5)); } else { loc = new Locale(localeCode); } items.put(loc.getDisplayName(), loc.toString()); } mLanguageDialogLabels = new CharSequence[items.size() + 1]; mLanguageDialogValues = new CharSequence[items.size() + 1]; mLanguageDialogLabels[0] = getResources().getString(R.string.language_system); mLanguageDialogValues[0] = ""; int i = 1; for (Map.Entry<String, String> e : items.entrySet()) { mLanguageDialogLabels[i] = e.getKey(); mLanguageDialogValues[i] = e.getValue(); i++; } mLanguageSelection = (ListPreference) getPreferenceScreen().findPreference("language"); mLanguageSelection.setEntries(mLanguageDialogLabels); mLanguageSelection.setEntryValues(mLanguageDialogValues); }
public static String getMessage(MessageSourceResolvable resolvable, Locale locale) { log.debug( "the locale is " + locale.getDisplayName() + " resolvable default message is " + resolvable.getDefaultMessage()); return ms.getMessage(resolvable, locale); }
public static void main(String[] args) throws java.lang.Exception { Locale[] locales = Locale.getAvailableLocales(); // sorting locales sortArray(Collator.getInstance(Locale.ENGLISH), locales); // comment first System.out.println("/*"); int i = 0; for (Locale l : locales) { i++; if (l.getDisplayName().contains("(")) continue; if (blacklisted(i)) continue; System.out.print(" * " + i + " " + l.getDisplayName()); System.out.println(); } System.out.println(" */"); // body i = 0; for (Locale l : locales) { i++; if (blacklisted(i)) continue; if (l.getDisplayName().contains("(")) continue; DateFormatSymbols symbols = new DateFormatSymbols(l); String[] dayNames = symbols.getShortWeekdays(); // precompiler condition System.out.println("#if LANG == " + i); System.out.println("// " + l.getDisplayName()); // day array body System.out.println("static const char* const DAYS[] = {"); for (String s : dayNames) { if (s.length() == 0) continue; String norm = Normalizer.normalize(s, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""); System.out.print("\"" + norm.toUpperCase() + "\","); System.out.println(" /* " + s + " */"); } System.out.println("};"); System.out.println("#endif "); System.out.println(); } }
public static void buildAvailableLanguages() { availableTtsLocales.clear(); Locale[] systemLocales = Locale.getAvailableLocales(); for (Locale loc : systemLocales) { try { int retCode = mTts.isLanguageAvailable(loc); if (retCode >= TextToSpeech.LANG_COUNTRY_AVAILABLE) { availableTtsLocales.add(loc); } else { Timber.v( "ReadText.buildAvailableLanguages() :: %s not available (error code %d)", loc.getDisplayName(), retCode); } } catch (IllegalArgumentException e) { Timber.e("Error checking if language " + loc.getDisplayName() + " available"); } } }
private static int getLayoutDirectionFromFirstChar(Locale locale) { switch (Character.getDirectionality(locale.getDisplayName(locale).charAt(0))) { case SpinnerCompat.MODE_DROPDOWN /*1*/: case DrawerLayout.STATE_SETTLING /*2*/: return 1; default: return 0; } }
@Test public void testListAllSerbianCountries() { for (final Locale aLocale : CollectionHelper.getSorted(Locale.getAvailableLocales(), new ComparatorLocale())) if (aLocale.getLanguage().equals("sr") || aLocale.getLanguage().equals("sh") || aLocale.getLanguage().equals("bs")) s_aLogger.info(aLocale.toString() + ": " + aLocale.getDisplayName()); }
private String formatLocale(Locale l) { return (l.getDisplayName() + " : " + l.getLanguage() + ' ' + l.getCountry() + ' ' + l.getVariant()); }
public static String getLocaleDisplayName(Context context, String localeStr) { if (TextUtils.isEmpty(localeStr)) { // CAVEAT: localeStr should not be null because a null locale stands for the system // locale in UserDictionary.Words.addWord. return context.getResources().getString(R.string.user_dict_settings_all_languages); } final Locale locale = LocaleUtils.constructLocaleFromString(localeStr); final Locale systemLocale = context.getResources().getConfiguration().locale; return locale.getDisplayName(systemLocale); }
private static void showLocale(Locale locale) { System.out.print("Locale(\""); System.out.print(locale.getLanguage()); System.out.print("\",\""); System.out.print(locale.getCountry()); System.out.print("\",\""); System.out.print(locale.getVariant()); System.out.print("\") \t "); System.out.println(locale.getDisplayName()); }
public static String getMessage(String code, Object[] args, Locale locale) { log.debug( "get the " + code + " values; the args is " + Arrays.toString(args) + "; the locale is " + locale.getDisplayName()); return ms.getMessage(code, args, locale); }
// http://b/2611311; if there's no display language/country/variant, use the raw codes. public void test_getDisplayName_unknown() throws Exception { Locale unknown = new Locale("xx", "YY", "Traditional"); assertEquals("xx", unknown.getLanguage()); assertEquals("YY", unknown.getCountry()); assertEquals("Traditional", unknown.getVariant()); assertEquals("xx", unknown.getDisplayLanguage()); assertEquals("YY", unknown.getDisplayCountry()); assertEquals("TRADITIONAL", unknown.getDisplayVariant()); assertEquals("xx (YY,TRADITIONAL)", unknown.getDisplayName()); }
public static final Locale getLanguage(final String language, final Locale locale) { synchronized (localeMap) { if (localeMap.containsKey(locale) == false) { final Map<String, Locale> m = new HashMap<String, Locale>(); for (final Locale lc : Locale.getAvailableLocales()) { m.put(lc.getDisplayName(locale), lc); } localeMap.put(locale, m); } } return localeMap.get(locale).get(language); }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean hasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, hasFocus); if (value instanceof Locale) { Locale locale = (Locale) value; setText(locale.getDisplayName(locale)); } return this; }
public static Choice[] getNLChoices() { Locale[] locales = Locale.getAvailableLocales(); Choice[] choices = new Choice[locales.length]; for (int i = 0; i < locales.length; i++) { Locale locale = locales[i]; choices[i] = new Choice( locale.toString(), locale.toString() + " - " + locale.getDisplayName()); // $NON-NLS-1$ } return choices; }
// http://b/2611311; if there's no display language/country/variant, use the raw codes. public void test_getDisplayName_invalid() throws Exception { Locale invalid = new Locale("AaBbCc", "DdEeFf", "GgHhIi"); assertEquals("aabbcc", invalid.getLanguage()); assertEquals("DDEEFF", invalid.getCountry()); assertEquals("GgHhIi", invalid.getVariant()); // Android using icu4c < 49.2 returned empty strings for display language, country, // and variant, but a display name made up of the raw strings. // Newer releases return slightly different results, but no less unreasonable. assertEquals("aabbcc", invalid.getDisplayLanguage()); assertEquals("", invalid.getDisplayCountry()); assertEquals("DDEEFF_GGHHII", invalid.getDisplayVariant()); assertEquals("aabbcc (DDEEFF,DDEEFF_GGHHII)", invalid.getDisplayName()); }
private void onLocaleChanged(Locale paramLocale) { Resources localResources = getActivity().getResources(); Configuration localConfiguration1 = localResources.getConfiguration(); Configuration localConfiguration2 = new Configuration(); localConfiguration2.locale = paramLocale; localResources.updateConfiguration(localConfiguration2, null); localResources.updateConfiguration(localConfiguration1, null); mHandler.removeCallbacks(mUpdateLocale); mCurrentLocale = paramLocale; SetupStats.addEvent( SetupStats.Categories.SETTING_CHANGED, SetupStats.Action.CHANGE_LOCALE, SetupStats.Label.LOCALE, mCurrentLocale.getDisplayName()); mHandler.postDelayed(mUpdateLocale, 1000); }
@RequestMapping(value = "check-User", method = RequestMethod.POST) public String chekUser( @Valid @ModelAttribute User user, BindingResult result, ModelMap modelMap, RedirectAttributes attributes, Locale locale) { logger.info("check-User"); if (result.hasErrors()) { return "home"; } attributes.addFlashAttribute( "locale", messageSource.getMessage("locale", new String[] {locale.getDisplayName(locale)}, locale)); return "redirect:/redirectController"; }
public static void main(String[] args) { System.out.println("The default locale is : " + Locale.getDefault()); Locale[] locales = Locale.getAvailableLocales(); System.out.printf("No. of other available locales is: %d, and they are: %n", locales.length); for (Locale locale : locales) { if (locale.getLanguage().equals("en")) { System.out.printf( "Locale code: %s and it stands for %s %n", locale, locale.getDisplayName()); } // System.out.printf("Locale code: %s and it stands for %s %n", locale, // locale.getDisplayName()); } }
/** * @param locale * @return cast a Locale to a String */ public static String getDisplayName(Locale locale) { String lang = locale.getLanguage(); String country = locale.getCountry(); synchronized (localeAlias) { Iterator<Entry<String, Locale>> it = localeAlias.entrySet().iterator(); Map.Entry<String, Locale> entry; while (it.hasNext()) { entry = it.next(); // Object qkey=it.next(); Locale curr = entry.getValue(); if (lang.equals(curr.getLanguage()) && country.equals(curr.getCountry())) { return entry.getKey().toString(); } } } return locale.getDisplayName(Locale.ENGLISH); }
public String getLocaleName(String localeLanguage, String localeCountry) { String value = localeLanguage; if (!Format.isNullOrEmpty(localeCountry)) { value += "-" + localeCountry; } Locale locales[] = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { Locale locale = locales[i]; String localeValue = locale.getLanguage(); if (!Format.isNullOrEmpty(locale.getCountry())) { localeValue += "-" + locale.getCountry(); } if (value.equals(localeValue)) { return locale.getDisplayName(); } } return null; }
/** * The method receives a date format mask in the necessary localization * * @param locale localization (type of Locale) * @param useSecond flag of existence of seconds (if true, a format of date contains seconds) * @return формат даты и времени (type of SimpleDateFormat) */ public static synchronized SimpleDateFormat getDateFormatterByLocale( Locale locale, boolean useSecond) { SimpleDateFormat dateFormatter; if (locale.getDisplayName().equalsIgnoreCase("en_us")) { dateFormatter = useSecond ? new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") : new SimpleDateFormat("MM/dd/yyyy HH:mm"); } else { dateFormatter = useSecond ? new SimpleDateFormat("dd.MM.yyyy HH:mm:ss") : new SimpleDateFormat("dd.MM.yyyy HH:mm"); } return dateFormatter; }
public static boolean setNewLocale(Context context, Locale locale) { Configuration config = context.getResources().getConfiguration(); config.locale = locale; // Locale.setDefault(locale); context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); Log.d("Gibberbot", "locale = " + locale.getDisplayName()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Editor prefEdit = prefs.edit(); prefEdit.putString(ImApp.PREF_DEFAULT_LOCALE, locale.getISO3Language()); prefEdit.commit(); return true; }
@Override public View getView(final int position, final View convertView, final ViewGroup parent) { final View view; if (convertView == null) { view = m_inflater.inflate(R.layout.locale_listitem, parent, false); } else { view = convertView; } final Locale locale = getItem(position); final TextView text1 = (TextView) view.findViewById(R.id.textView1); final TextView text2 = (TextView) view.findViewById(R.id.textView2); text1.setText(locale.getDisplayName()); text2.setText(locale.toString()); return view; }
static { if (!Configuration.get("DISABLE_L10N").equals("yes")) { String fn = "messages_" + currentLocale.getLanguage() + ".properties"; if (Configuration.get("LOCALES_DIR") != "") { System.out.print("Look " + fn + " at: " + Configuration.get("LOCALES_DIR") + " "); try { messages.load( new FileInputStream(Configuration.get("LOCALES_DIR") + File.separator + fn)); System.out.println(" - found"); } catch (IOException ex) { // Do nothing ... System.out.println(" - not found"); ex.printStackTrace(); } } if (messages.size() == 0) { try { messages.load(Local.class.getResourceAsStream("localmessages/" + fn)); } catch (Exception e) { // Do nothing ... } } } else { currentLocale = new Locale("en", "US"); /*DEBUG*/ System.out.println("* DEBUG: Locales are disabled"); } if (messages.size() == 0) messages = null; /** * DEBUG PURPOSES ** */ System.out.println("Default locale: " + currentLocale.getDisplayName()); if (messages != null) { System.out.println( "Use local messages: messages_" + currentLocale.getLanguage() + ".properties"); } else { System.out.println( "* DEBUG: Locales are disabled or not found: messages_" + currentLocale.getLanguage() + ".properties"); } /** ******************* */ }