List of usage examples for java.util Locale getAvailableLocales
public static Locale[] getAvailableLocales()
From source file:ca.travelagency.components.fields.TravelDocumentField.java
@Override protected Iterator<String> getChoices(String input) { if (StringUtils.isEmpty(input)) { return Collections.<String>emptyList().iterator(); }// w w w.j av a2s . c o m SortedSet<String> choices = new TreeSet<String>(); Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { String country = locale.getDisplayCountry().toUpperCase(); if (country.startsWith(input.toUpperCase())) { String value = getLocalizer().getString(country, this, country); if (StringUtils.isBlank(value)) { value = country; } choices.add(WordUtils.capitalize(StringUtils.lowerCase(value + " " + suffix))); if (choices.size() == DISPLAY_MAX_SIZE) { break; } } } return choices.iterator(); }
From source file:com.erudika.para.i18n.CurrencyUtils.java
private CurrencyUtils() { Locale[] locales = Locale.getAvailableLocales(); try {/*from w w w .j a v a 2s .c om*/ for (Locale l : locales) { if (!StringUtils.isBlank(l.getCountry())) { COUNTRY_TO_LOCALE_MAP.put(l.getCountry(), l); Currency c = Currency.getInstance(l); if (c != null) { CURRENCY_TO_LOCALE_MAP.put(c.getCurrencyCode(), l); CURRENCIES_MAP.put(c.getCurrencyCode(), getCurrencyName(c.getCurrencyCode(), Locale.US).concat(" ").concat(c.getSymbol(l))); } } } // overwrite main locales CURRENCY_TO_LOCALE_MAP.put("USD", Locale.US); CURRENCY_TO_LOCALE_MAP.put("EUR", Locale.FRANCE); } catch (Exception e) { logger.error(null, e); } }
From source file:com.prowidesoftware.swift.utils.IsoUtils.java
private IsoUtils() { /*//from ww w .j av a 2 s .c o m * load currencies from all available locale instances * * TODO This should be replaced by Currency.getAvailableCurrencies() once Prowide Core in migrated to Java7 */ currencies = new HashSet<String>(); for (Locale locale : Locale.getAvailableLocales()) { try { String val = Currency.getInstance(locale).getCurrencyCode(); if (!currencies.contains(val)) { currencies.add(val); } } catch (Exception e) { log.log(Level.FINEST, "error loading currencies from locale " + locale, e); } } countries = new HashSet<String>(Arrays.asList(Locale.getISOCountries())); // Add country code for Kosovo, not yet in ISO but used by SWIFT addCountry("XK"); }
From source file:com.restfb.util.InsightUtilsTest.java
@BeforeClass public static void beforeClass() throws ParseException { for (Locale locale : Locale.getAvailableLocales()) { if (locale.toString().equals("en_US")) { DEFAULT_LOCALE = locale;/* w w w. j av a 2 s .c om*/ break; } } Assert.assertNotNull(DEFAULT_LOCALE); sdfUTC = newSimpleDateFormat("yyyyMMdd_HHmm", DEFAULT_LOCALE, UTC_TIMEZONE); sdfPST = newSimpleDateFormat("yyyyMMdd_HHmm", DEFAULT_LOCALE, PST_TIMEZONE); d20101204_0000pst = sdfPST.parse("20101204_0000"); d20101205_0000pst = sdfPST.parse("20101205_0000"); }
From source file:com.cyclopsgroup.tornado.ui.view.user.UserProfile.java
/** * Override method execute in class UserProfile * * @see com.cyclopsgroup.waterview.Module#execute(com.cyclopsgroup.waterview.RuntimeData, com.cyclopsgroup.waterview.Context) *//*from www.jav a2 s .co m*/ public void execute(RuntimeData data, Context context) throws Exception { RuntimeUser user = RuntimeUser.getInstance(data); PersistenceManager persist = (PersistenceManager) lookup(PersistenceManager.ROLE); User u = (User) persist.load(User.class, user.getId()); context.put("userObject", u); TreeMap languages = new TreeMap(); TreeMap countries = new TreeMap(); Locale[] availableLocales = Locale.getAvailableLocales(); for (int i = 0; i < availableLocales.length; i++) { Locale locale = availableLocales[i]; DefaultSelectOption lang = new DefaultSelectOption(locale.getLanguage(), locale.getDisplayLanguage(data.getLocale()) + '(' + locale.getLanguage() + ')'); languages.put(locale.getLanguage(), lang); if (StringUtils.isNotEmpty(locale.getCountry())) { DefaultSelectOption cout = new DefaultSelectOption(locale.getCountry(), locale.getDisplayCountry(data.getLocale()) + '(' + locale.getCountry() + ')'); countries.put(locale.getCountry(), cout); } } context.put("countries", countries.values()); context.put("languages", languages.values()); }
From source file:org.gcaldaemon.gui.Messages.java
public static final Locale[] getAvailableLocales() { LinkedList list = new LinkedList(); list.addLast(Locale.ENGLISH); try {/* www.j ava 2s . co m*/ Locale[] availables = Locale.getAvailableLocales(); String programDir = System.getProperty("gcaldaemon.program.dir", "/Progra~1/GCALDaemon"); File langDir = new File(programDir, "lang"); if (langDir.isDirectory()) { String[] names = langDir.list(); String name; int s, e; for (int i = 0; i < names.length; i++) { name = names[i]; if (name.equals("messages-en.txt")) { continue; } s = name.indexOf('-'); e = name.indexOf('.', s); if (s != -1 && e != -1) { name = name.substring(s + 1, e); Locale locale = null; for (s = 0; s < availables.length; s++) { if (name.equals(availables[s].getCountry().toLowerCase())) { locale = availables[s]; break; } } if (locale == null) { locale = new Locale(name); } list.add(locale); } } } } catch (Exception ignored) { log.warn(ignored); } Locale[] array = new Locale[list.size()]; list.toArray(array); return array; }
From source file:org.netxilia.api.impl.format.CurrencyFormatter.java
@Override public void init() { if (country != null) { if (country.equals("EUR")) { setLocaleObject(new Locale("fr", "FR", "EUR")); } else {/* w ww . j av a 2 s .c om*/ Locale setLocale = Locale.getDefault(); for (Locale locale : Locale.getAvailableLocales()) { if (country.equalsIgnoreCase(locale.getCountry())) { setLocale = locale; break; } } setLocaleObject(setLocale); } } else { setLocaleObject(Locale.getDefault()); } }
From source file:com.hichinaschool.flashcards.anki.ReadText.java
public static void textToSpeech(String text, long did, int ord, int qa) { mTextToSpeak = text;/*from ww w .j a v a2s .co m*/ mQuestionAnswer = qa; mDid = did; mOrd = ord; String language = getLanguage(mDid, mOrd, mQuestionAnswer); if (availableTtsLocales.isEmpty()) { Locale[] systemLocales = Locale.getAvailableLocales(); for (Locale loc : systemLocales) { if (mTts.isLanguageAvailable(loc) == TextToSpeech.LANG_COUNTRY_AVAILABLE) { availableTtsLocales.add(new String[] { loc.getISO3Language(), loc.getDisplayName() }); } } } // Check, if stored language is available for (int i = 0; i < availableTtsLocales.size(); i++) { if (language.equals(NO_TTS)) { return; } else if (language.equals(availableTtsLocales.get(i)[0])) { speak(mTextToSpeak, language); return; } } // Otherwise ask Resources res = mReviewer.getResources(); StyledDialog.Builder builder = new StyledDialog.Builder(mReviewer); if (availableTtsLocales.size() == 0) { builder.setTitle(res.getString(R.string.no_tts_available_title)); builder.setMessage(res.getString(R.string.no_tts_available_message)); builder.setIcon(R.drawable.ic_dialog_alert); builder.setPositiveButton(res.getString(R.string.ok), null); } else { ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>(); final ArrayList<String> dialogIds = new ArrayList<String>(); builder.setTitle(R.string.select_locale_title); // Add option: "no tts" dialogItems.add(res.getString(R.string.tts_no_tts)); dialogIds.add(NO_TTS); for (int i = 0; i < availableTtsLocales.size(); i++) { dialogItems.add(availableTtsLocales.get(i)[1]); dialogIds.add(availableTtsLocales.get(i)[0]); } String[] items = new String[dialogItems.size()]; dialogItems.toArray(items); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MetaDB.storeLanguage(mReviewer, mDid, mOrd, mQuestionAnswer, dialogIds.get(which)); speak(mTextToSpeak, dialogIds.get(which)); } }); } builder.create().show(); }
From source file:org.openmrs.web.taglib.ConceptTag.java
public int doStartTag() throws JspException { ConceptService cs = Context.getConceptService(); // Search for a concept by id if (conceptId != null) { c = cs.getConcept(conceptId);/*from w ww . j a v a2 s . c o m*/ } else if (conceptName != null) { c = cs.getConceptByName(conceptName); } if (c == null) { if (conceptId != null && conceptId > 0) { log.warn("ConceptTag is unable to find a concept with conceptId '" + conceptId + "'"); } if (conceptName != null) { log.warn("ConceptTag is unable to find a concept with conceptName '" + conceptName + "'"); } return SKIP_BODY; } pageContext.setAttribute(var, c); log.debug("Found concept with id " + conceptId + ", set to variable: " + var); // If user specifies a locale in the tag, try to find a matching locale. Otherwise, use the user's default locale Locale loc = Context.getLocale(); if (StringUtils.isNotEmpty(locale)) { Locale[] locales = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { if (locale.equals(locales[i].toString())) { loc = locales[i]; break; } } } if (nameVar != null) { ConceptName cName = c.getName(loc); pageContext.setAttribute(nameVar, cName); log.debug("Retrieved name " + cName.getName() + ", set to variable: " + nameVar); } if (shortestNameVar != null) { pageContext.setAttribute(shortestNameVar, c.getShortestName(loc, false)); } if (numericVar != null) { pageContext.setAttribute(numericVar, cs.getConceptNumeric(conceptId)); } // If the Concept is a Set, get members of that Set if (c.isSet() && setMemberVar != null) { pageContext.setAttribute(setMemberVar, Context.getConceptService().getConceptsByConceptSet(c)); } // If the Concept is a Set, get members of that Set if (c.isSet() && setMemberVar != null) { pageContext.setAttribute(setMemberVar, Context.getConceptService().getConceptsByConceptSet(c)); } return EVAL_BODY_BUFFERED; }
From source file:org.primeframework.mvc.control.form.CountrySelect.java
/** * Adds the countries Map and then calls super. *//*ww w . j a v a 2s . c o m*/ @Override protected Map<String, Object> makeParameters() { LinkedHashMap<String, String> countries = new LinkedHashMap<String, String>(); if (attributes.containsKey("includeBlank") && (Boolean) attributes.get("includeBlank")) { countries.put("", ""); } String preferred = (String) attributes.get("preferredCodes"); if (preferred != null) { String[] parts = preferred.split(","); for (String part : parts) { Locale locale = new Locale("", part); countries.put(part, locale.getDisplayCountry(locale)); } } SortedSet<Locale> alphabetical = new TreeSet<Locale>(new LocaleComparator(locale)); Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { if (StringUtils.isNotBlank(locale.getCountry()) && StringUtils.isNotBlank(locale.getDisplayCountry(locale))) { alphabetical.add(locale); } } for (Locale locale : alphabetical) { if (!countries.containsKey(locale.getCountry())) { countries.put(locale.getCountry(), locale.getDisplayCountry(this.locale)); } } attributes.put("items", countries); return super.makeParameters(); }