List of usage examples for java.util Locale getAvailableLocales
public static Locale[] getAvailableLocales()
From source file:ch.entwine.weblounge.common.impl.language.LanguageUtils.java
/** * Returns the language object identified by the language identifier. * /* w w w . j av a 2 s .c om*/ * @param languageCode * the language identifier * @return the language * @throws UnknownLanguageException * if there is no language for the given locale */ public static Language getLanguage(String languageCode) throws UnknownLanguageException { Language language = systemLanguages.get(languageCode); if (language != null) return language; for (Locale locale : Locale.getAvailableLocales()) { if (locale.getLanguage().equals(languageCode)) { language = new LanguageImpl(new Locale(languageCode, "", "")); systemLanguages.put(languageCode, language); break; } } if (language == null) throw new UnknownLanguageException(languageCode); return language; }
From source file:org.apache.openmeetings.web.pages.install.TestInstall.java
@Before public void setUp() throws IOException { log.info("Going to perform setup for TestInstall"); AbstractSpringTest.setOmHome();/*from w w w. j a v a 2 s.c om*/ setWicketApplicationName(DEFAULT_APP_NAME); tempFolder = Files.createTempDirectory("omtempdb").toFile(); setDerbyHome(tempFolder); tester = getWicketTester((Application) ensureApplication(-1L)); assertNotNull("Web session should not be null", WebSession.get()); Locale[] locales = Locale.getAvailableLocales(); tester.getSession().setLocale(locales[rnd.nextInt(locales.length)]); log.info("Setup complete"); }
From source file:edu.ku.brc.specify.prefs.SystemPrefs.java
/** * Constructor./*from www . ja v a2 s .c om*/ */ public SystemPrefs() { createForm("Preferences", "System"); JButton clearCache = form.getCompById("clearcache"); clearCache.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { clearCache(); } }); ValBrowseBtnPanel browse = form.getCompById("7"); if (browse != null) { oldSplashPath = localPrefs.get(SPECIFY_BG_IMG_PATH, null); browse.setValue(oldSplashPath, null); } final ValComboBox localeCBX = form.getCompById("5"); localeCBX.getComboBox().setRenderer(new LocaleRenderer()); localeCBX.setEnabled(false); SwingWorker workerThread = new SwingWorker() { protected int inx = -1; @Override public Object construct() { Vector<Locale> locales = new Vector<Locale>(); Collections.addAll(locales, Locale.getAvailableLocales()); Collections.sort(locales, new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { return o1.getDisplayName().compareTo(o2.getDisplayName()); } }); int i = 0; String language = AppPreferences.getLocalPrefs().get("locale.lang", Locale.getDefault().getLanguage()); String country = AppPreferences.getLocalPrefs().get("locale.country", Locale.getDefault().getCountry()); String variant = AppPreferences.getLocalPrefs().get("locale.var", Locale.getDefault().getVariant()); Locale prefLocale = new Locale(language, country, variant); int justLangIndex = -1; Locale cachedLocale = Locale.getDefault(); for (Locale l : locales) { try { Locale.setDefault(l); ResourceBundle rb = ResourceBundle.getBundle("resources", l); boolean isOK = (l.getLanguage().equals("en") && StringUtils.isEmpty(l.getCountry())) || (l.getLanguage().equals("pt") && l.getCountry().equals("PT")); if (isOK && rb.getKeys().hasMoreElements()) { if (l.getLanguage().equals(prefLocale.getLanguage())) { justLangIndex = i; } if (l.equals(prefLocale)) { inx = i; } localeCBX.getComboBox().addItem(l); i++; } } catch (MissingResourceException ex) { } } if (inx == -1 && justLangIndex > -1) { inx = justLangIndex; } Locale.setDefault(cachedLocale); return null; } @Override public void finished() { UIValidator.setIgnoreAllValidation("SystemPrefs", true); localeCBX.setEnabled(true); localeCBX.getComboBox().setSelectedIndex(inx); JTextField loadingLabel = form.getCompById("6"); if (loadingLabel != null) { loadingLabel.setText(UIRegistry.getResourceString("LOCALE_RESTART_REQUIRED")); } UIValidator.setIgnoreAllValidation("SystemPrefs", false); } }; // start the background task workerThread.start(); ValCheckBox chk = form.getCompById("2"); chk.setValue(localPrefs.getBoolean(VERSION_CHECK, true), "true"); chk = form.getCompById("3"); chk.setValue(remotePrefs.getBoolean(SEND_STATS, true), "true"); chk = form.getCompById("9"); chk.setValue(remotePrefs.getBoolean(SEND_ISA_STATS, true), "true"); chk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class); if (collection != null) { String isaNumber = collection.getIsaNumber(); if (StringUtils.isNotEmpty(isaNumber) && !((JCheckBox) e.getSource()).isSelected()) { UIRegistry.showLocalizedMsg("ISA_STATS_WARNING"); } } } }); // Not sure why the form isn't picking up the pref automatically /* remove if worldwind is broken*/ValCheckBox useWWChk = form.getCompById(USE_WORLDWIND); /* remove if worldwind is broken*/ValCheckBox hasOGLChk = form.getCompById(SYSTEM_HasOpenGL); /* remove if worldwind is broken*/useWWChk.setValue(localPrefs.getBoolean(USE_WORLDWIND, false), null); /* remove if worldwind is broken*/hasOGLChk.setValue(localPrefs.getBoolean(SYSTEM_HasOpenGL, false), null); /* remove if worldwind is broken*/hasOGLChk.setEnabled(false); //ValCheckBox askCollChk = form.getCompById(ALWAYS_ASK_COLL); //askCollChk.setValue(localPrefs.getBoolean(ALWAYS_ASK_COLL, false), null); }
From source file:nz.co.senanque.localemanagement.XMLMessageSource.java
@SuppressWarnings("unchecked") @Override// w ww .j av a 2 s. co m public void afterPropertiesSet() throws Exception { m_resource.getInputStream(); Document doc = null; try { InputStream in = getResource().getInputStream(); SAXBuilder sax = new SAXBuilder(); doc = sax.build(in); } catch (Exception e) { throw new RuntimeException(e); } Locale defaultLocale = Locale.getDefault(); for (Element e : (List<Element>) doc.getRootElement().getChildren("locale")) { String l = e.getAttributeValue("name"); if (l == null) { l = defaultLocale.toString(); } for (Locale locale : Locale.getAvailableLocales()) { if (locale.toString().equals(l)) { Map<String, String> values = new HashMap<String, String>(); m_map.put(locale, values); for (Element e1 : (List<Element>) e.getChildren("entry")) { values.put(e1.getAttributeValue("name"), e1.getAttributeValue("value")); } } } } }
From source file:mo.iguideu.ui.initGuideProfile.FragmentInitGuideDataStep2.java
public void refreshSupportLocales() { String[] countries = Locale.getISOCountries(); Locale[] locales = Locale.getAvailableLocales(); Map<String, String> languagesMap = new TreeMap<String, String>(); for (Locale obj : locales) { if ((obj.getDisplayCountry() != null) && (!"".equals(obj.getDisplayCountry()))) { languagesMap.put(obj.getCountry(), obj.getLanguage()); }/*from w w w .j a v a2 s .c o m*/ } for (String countryCode : countries) { Locale obj = new Locale("", countryCode); if (languagesMap.get(countryCode) != null) { obj = new Locale(languagesMap.get(countryCode), countryCode); if (!obj.getCountry().equals("TW") && !obj.getCountry().equals("JP") && !obj.getCountry().equals("CN")) supportLocale.add(obj); } } }
From source file:hudson.model.AllView.java
/** * Corrects the name of the {@link AllView} if and only if the {@link AllView} is the primary view and * its name is one of the localized forms of {@link Messages#_Hudson_ViewName()} and the user has not opted out of * fixing the view name by setting the system property {@code hudson.mode.AllView.JENKINS-38606} to {@code false}. * Use this method to round-trip the primary view name, e.g. * {@code primaryView = migrateLegacyPrimaryAllViewLocalizedName(views, primaryView)} * <p>//from w w w . ja v a 2s . c o m * NOTE: we can only fix the localized name of an {@link AllView} if it is the primary view as otherwise urls * would change, whereas the primary view is special and does not normally get accessed by the * {@code /view/_name_} url. (Also note that there are some cases where the primary view will get accessed by * its {@code /view/_name_} url which will then fall back to the primary view) * * @param views the list of views. * @param primaryView the current primary view name. * @return the primary view name - this will be the same as the provided primary view name unless a JENKINS-38606 * matching name is detected, in which case this will be the new name of the primary view. * @since 2.37 */ @Nonnull public static String migrateLegacyPrimaryAllViewLocalizedName(@Nonnull List<View> views, @Nonnull String primaryView) { if (DEFAULT_VIEW_NAME.equals(primaryView)) { // modern name, we are safe return primaryView; } if (SystemProperties.getBoolean(AllView.class.getName() + ".JENKINS-38606", true)) { AllView allView = null; for (View v : views) { if (DEFAULT_VIEW_NAME.equals(v.getViewName())) { // name conflict, we cannot rename the all view anyway return primaryView; } if (StringUtils.equals(v.getViewName(), primaryView)) { if (v instanceof AllView) { allView = (AllView) v; } else { // none of our business fixing as we can only safely fix the primary view return primaryView; } } } if (allView != null) { // the primary view is an AllView but using a non-default name for (Locale l : Locale.getAvailableLocales()) { if (primaryView.equals(Messages._Hudson_ViewName().toString(l))) { // bingo JENKINS-38606 detected LOGGER.log(Level.INFO, "JENKINS-38606 detected for AllView in {0}; renaming view from {1} to {2}", new Object[] { allView.owner, primaryView, DEFAULT_VIEW_NAME }); allView.name = DEFAULT_VIEW_NAME; return DEFAULT_VIEW_NAME; } } } } return primaryView; }
From source file:org.glucosio.android.activity.HelloActivity.java
private void initCountrySpinner(final LocaleHelper localeHelper) { // Get countries list from locale ArrayList<String> countries = new ArrayList<>(); Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { String country = locale.getDisplayCountry(); if ((country.trim().length() > 0) && (!countries.contains(country))) { countries.add(country);//from w w w. j a v a 2 s .c om } } Collections.sort(countries); // Populate Spinners with array countrySpinner.setItemsArray(countries); // Get locale country name and set the spinner String localCountry = localeHelper.getDeviceLocale().getDisplayCountry(); setSelection(localCountry, countrySpinner); }
From source file:org.keyboardplaying.xtt.ui.i18n.I18nHelper.java
/** * Returns a list of all locales a bundle has been written for. * * @return a list of all locales availables within the application *///from w w w . j av a 2 s . co m public List<Locale> getAvailableLocales() { /* Convert base name to a path. */ String bundlePath = BUNDLE_BASE_NAME.replaceAll("\\.", "/") + "_%s.properties"; List<Locale> available = new ArrayList<>(); /* Loop over all locales to find those we do support. */ // Get a list of all locales the JVM supports Locale[] locales = Locale.getAvailableLocales(); // Loop over those to find available locales for (Locale locale : locales) { URL bundleUrl = ClassLoader.getSystemResource(String.format(bundlePath, locale.toString())); if (bundleUrl != null) { available.add(locale); } } /* Return the list. */ return available; }
From source file:org.businessmanager.geodb.OpenGeoDBImpl.java
public List<Country> getListOfCountries(String language) { List<Country> countries = null; if (language == null) { countries = countryMap.get(Locale.getDefault().getLanguage()); } else {//from w w w .ja v a2s. c om countries = countryMap.get(language); } if (countries == null) { countries = new ArrayList<Country>(); } else { return countries; } List<String> codes = new ArrayList<String>(); Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { String code = locale.getCountry(); // do not insert a country more than once if (codes.contains(code)) { continue; } String name = null; if (language != null) { name = locale.getDisplayCountry(Locale.forLanguageTag(language)); } else { name = locale.getDisplayCountry(); } if (!"".equals(code) && !"".equals(name)) { countries.add(new Country(code, name)); codes.add(code); } } Collections.sort(countries, Country.getComparator()); Country defaultCountry = findDefaultCountry(countries); if (defaultCountry != null) { countries.add(0, defaultCountry); } if (language == null) { countryMap.put(Locale.getDefault().getLanguage(), countries); } else { countryMap.put(language, countries); } return countries; }
From source file:de.hybris.platform.acceleratorservices.web.payment.controllers.HostedOrderPageMockController.java
@ModelAttribute("billingCountries") public List<SelectOption> getBillingCountries() { final List<SelectOption> countries = new ArrayList<SelectOption>(); final Locale[] locales = Locale.getAvailableLocales(); final Map<String, String> countryMap = new HashMap<String, String>(); for (final Locale locale : locales) { final String code = locale.getCountry(); final String name = locale.getDisplayCountry(); // putting in a map to remove duplicates if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(name)) { countryMap.put(code, name);/*from w w w . ja v a 2 s. com*/ } } for (final String key : countryMap.keySet()) { countries.add(new SelectOption(key, countryMap.get(key))); } Collections.sort(countries, CountryComparator.INSTANCE); return countries; }