List of usage examples for java.util Locale getCountry
public String getCountry()
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 ww . j a v a2 s.c om } 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:org.batoo.common.util.StringUtils.java
/** * Determine the RFC 3066 compliant language tag, as used for the HTTP "Accept-Language" header. * /*from w w w .j av a2s .c om*/ * @param locale * the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as String */ public static String toLanguageTag(Locale locale) { return locale.getLanguage() + (StringUtils.hasText(locale.getCountry()) ? "-" + locale.getCountry() : ""); }
From source file:iqq.app.core.service.impl.I18nServiceImpl.java
private ResourceBundle getResourceBundle(Locale locale) { BufferedInputStream bis = null; try {/* w ww .j av a 2s. com*/ // ??_?_?.properties String flag = locale.getLanguage() + "_" + locale.getCountry(); String filename = I18N_DIR + I18N_BUNDLE + "_" + flag + ".properties"; ResourceBundle resourceBundle = resourceBundleMap.get(flag); // ??? if (resourceBundle != null) return resourceBundle; if (!new File(filename).exists()) { filename = I18N_DIR + I18N_BUNDLE + ".properties"; } LOG.debug(filename); bis = new BufferedInputStream(new FileInputStream(filename)); resourceBundle = new PropertyResourceBundle(bis); resourceBundleMap.put(flag, resourceBundle); return resourceBundle; } catch (FileNotFoundException e) { LOG.error("?", e); } catch (IOException e) { LOG.error("??", e); } finally { if (bis != null) try { bis.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:de.matzefratze123.heavyspleef.core.i18n.YMLControl.java
@Override public List<Locale> getCandidateLocales(String baseName, Locale locale) { List<Locale> candidates = Lists.newArrayList(); candidates.add(locale);/*from ww w .j ava2 s . co m*/ if (!locale.getLanguage().isEmpty() && !locale.getCountry().isEmpty() && !locale.getVariant().isEmpty()) { candidates.add(new Locale(locale.getLanguage(), locale.getCountry())); candidates.add(new Locale(locale.getLanguage())); } else if (!locale.getLanguage().isEmpty() && !locale.getCountry().isEmpty()) { candidates.add(new Locale(locale.getLanguage())); } candidates.add(Locale.US); candidates.add(Locale.ROOT); return candidates; }
From source file:org.opendatakit.utilities.LocalizationUtilsTest.java
@Test public void testNormalizeDisplayName() throws JsonProcessingException { Map<String, Object> langMap = new TreeMap<String, Object>(); langMap.put("en_US", "This is a test"); langMap.put("en_GB", "Test is This"); langMap.put("en", "Huh Test"); langMap.put("fr", "Je suis"); langMap.put("default", "No way!"); Map<String, Object> topMap = new TreeMap<String, Object>(); topMap.put("text", langMap); String value = ODKFileUtils.mapper.writeValueAsString(topMap); Locale defaultLocale; String full_locale;//from www.j a va 2 s. c o m String match; Locale.setDefault(Locale.US); defaultLocale = Locale.getDefault(); full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry(); match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value); assertEquals("This is a test", match); Locale.setDefault(Locale.UK); defaultLocale = Locale.getDefault(); full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry(); match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value); assertEquals("Test is This", match); Locale.setDefault(Locale.CANADA); defaultLocale = Locale.getDefault(); full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry(); match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value); assertEquals("Huh Test", match); Locale.setDefault(Locale.CANADA_FRENCH); defaultLocale = Locale.getDefault(); full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry(); match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value); assertEquals("Je suis", match); Locale.setDefault(Locale.GERMANY); defaultLocale = Locale.getDefault(); full_locale = defaultLocale.getLanguage() + "_" + defaultLocale.getCountry(); match = LocalizationUtils.getLocalizedDisplayName(appName, tableId, full_locale, value); assertEquals("No way!", match); Locale.setDefault(Locale.US); }
From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java
public ProcessPuzzleLocale(Locale locale) { this(locale.getLanguage(), locale.getCountry(), locale.getVariant()); try {/*from w w w. ja v a2 s.c om*/ this.setLegalTender(new Currency("", java.util.Currency.getInstance(locale).toString())); } catch (IllegalArgumentException e) { } }
From source file:com.enonic.cms.business.localization.resource.LocalizationResourceBundleServiceImpl.java
private LocalizationResourceBundle createResourceBundle(Locale locale, ResourceKey defaultLocalizationResourceKey) { Properties props = new Properties(); String lang = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); props.putAll(loadBundle(defaultLocalizationResourceKey, "")); if (StringUtils.isNotEmpty(lang)) { lang = lang.toLowerCase();//www .j ava2 s . co m props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang)); } if (StringUtils.isNotEmpty(country)) { country = country.toLowerCase(); props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country)); } if (StringUtils.isNotEmpty(variant)) { variant = variant.toLowerCase(); props.putAll(loadBundle(defaultLocalizationResourceKey, "_" + lang + "_" + country + "_" + variant)); } return new LocalizationResourceBundle(props); }
From source file:com.baruckis.nanodegree.spotifystreamer.fragments.SettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Getting preferences from the preference resource. mCountryListPreference = (ListPreference) getPreferenceManager() .findPreference(getString(R.string.list_preference_country_code_key)); mNotificationSwitchPreference = (SwitchPreference) getPreferenceManager() .findPreference(getString(R.string.switch_preference_notification_key)); Preference sourcePreference = getPreferenceManager() .findPreference(getString(R.string.preference_source_key)); Preference authorPreference = getPreferenceManager() .findPreference(getString(R.string.preference_author_key)); Preference licencePreference = getPreferenceManager() .findPreference(getString(R.string.preference_licence_key)); Preference versionPreference = getPreferenceManager() .findPreference(getString(R.string.preference_version_key)); // Setting up to display a list of countries List<String> countriesCodesList = new ArrayList<String>(); List<String> countriesNamesList = new ArrayList<String>(); String[] countries = Locale.getISOCountries(); // will return a list of all 2-letter country codes defined in ISO 3166 for (String countryCode : countries) { Locale locale = new Locale("", countryCode); countriesCodesList.add(locale.getCountry()); countriesNamesList.add(locale.getDisplayCountry()); }// w w w . j a va 2s .c om final CharSequence[] countriesCodes = countriesCodesList .toArray(new CharSequence[countriesCodesList.size()]); final CharSequence[] countriesNames = countriesNamesList .toArray(new CharSequence[countriesNamesList.size()]); mCountryListPreference.setEntryValues(countriesCodes); mCountryListPreference.setEntries(countriesNames); mCountryListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { updateCountryListPreferenceSummary((String) newValue); return true; } }); // set initial default country if (mCountryListPreference.getValue() == null) { mCountryListPreference.setValue(Locale.getDefault().getCountry()); } updateCountryListPreferenceSummary(mCountryListPreference.getValue()); mNotificationSwitchPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { ((SwitchPreference) preference).setChecked((boolean) newValue); updateNotificationSwitchPreferenceIcon(); // When notification visibility is changed, inform service immediately to show or stop showing notification. Intent notificationIntent = new Intent(PlayerService.RECEIVE_BROADCAST_INTENT_NOTIFICATION); notificationIntent.putExtra(PlayerService.RECEIVE_BROADCAST_INTENT_NOTIFICATION, (boolean) newValue); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(notificationIntent); return true; } }); updateNotificationSwitchPreferenceIcon(); // on source preference click open web browser with the url link sourcePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String url = getString(R.string.preference_source_url); Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setData(Uri.parse(url)); startActivity(viewIntent); return true; } }); // on author preference click open web browser with the url link authorPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String url = getString(R.string.preference_author_url); Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setData(Uri.parse(url)); startActivity(viewIntent); return true; } }); // on licence preference click open fragment dialog with the message licencePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { MessageDialogFragment .newInstance(R.drawable.ic_certificate_grey600_36dp, getString(R.string.licence_title), getString(R.string.licence_body, getString(R.string.app_name), Utils.getAppVersionNumber(getActivity()))) .show(getFragmentManager(), MessageDialogFragment.TAG); return true; } }); // setting app version number String version = getString(R.string.preference_version_summary) + Utils.getAppVersionNumber(getActivity()); versionPreference.setSummary(version); }
From source file:com.github.mrstampy.gameboot.messages.context.GameBootContextLookup.java
@Override public ResponseContext lookup(Integer code, Locale locale, Object... parameters) { if (locale == null) { log.warn("Null locale, using root"); return lookup(code); }//ww w. j ava2s . co m if (isNotEmpty(locale.getCountry())) { String suffix = "_" + locale.getLanguage() + "_" + locale.getCountry(); Map<Integer, ResponseContext> map = getForLocale(suffix); if (map != null && map.containsKey(code)) return lookup(code, suffix, map, parameters); } String suffix = "_" + locale.getLanguage(); Map<Integer, ResponseContext> map = getForLocale(suffix); if (map != null && map.containsKey(code)) return lookup(code, suffix, map, parameters); return lookup(code, parameters); }
From source file:net.technicpack.launcher.lang.ResourceLoader.java
private String getCodeFromLocale(Locale locale) { if (locale.getLanguage().isEmpty()) { return "default"; } else if (locale.getCountry().isEmpty()) { return locale.getLanguage(); } else if (locale.getVariant().isEmpty()) { return String.format("%s,%s", locale.getLanguage(), locale.getCountry()); } else {/*from ww w. ja v a 2s . co m*/ return String.format("%s,%s,%s", locale.getLanguage(), locale.getCountry(), locale.getVariant()); } }