List of usage examples for java.util Locale getDisplayCountry
public String getDisplayCountry(Locale inLocale)
From source file:org.sisto.jeeplate.jsf.Oracle.java
public Map<String, String> localizedCountries() { Map<String, String> localized = new TreeMap<>(); Locale viewLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); this.countries.keySet().stream().forEach((key) -> { String val = (String) this.countries.get(key); Locale loc = new Locale("", val); String display = loc.getDisplayCountry(viewLocale); if (display.length() > 2) { localized.put(display, key); }//from w w w .j a v a2 s .c o m }); return localized; }
From source file:com.juce.JuceAppActivity.java
public static final String getLocaleValue (boolean isRegion) { java.util.Locale locale = java.util.Locale.getDefault(); return isRegion ? locale.getDisplayCountry (java.util.Locale.US) : locale.getDisplayLanguage (java.util.Locale.US); }
From source file:im.vector.VectorApp.java
/** * Convert a locale to a string// w w w .ja v a 2 s .c om * * @param locale the locale to convert * @return the string */ public static String localeToLocalisedString(Locale locale) { String res = locale.getDisplayLanguage(locale); if (!TextUtils.isEmpty(locale.getDisplayCountry(locale))) { res += " (" + locale.getDisplayCountry(locale) + ")"; } return res; }
From source file:org.apache.click.extras.control.CountrySelect.java
/** * Load the Country Select options if not defined, using all the available * countries. The option value will be the two letter uppercase ISO name of * the country as the value and the localized country name as the label. *///w w w. java 2 s. c o m protected void loadOptionList() { List optionList = getOptionList(); // Determine whether option list should be loaded if (optionList.size() == 1) { Option option = (Option) optionList.get(0); if (option.getValue().equals(Option.EMPTY_OPTION.getValue())) { // Continue and load option list } else { // Don't load list return; } } else if (optionList.size() > 1) { // Don't load list return; } Set<Option> countryList = new TreeSet<Option>(new OptionLabelComparator(getLocale())); String[] isoCountries = Locale.getISOCountries(); Locale userLocale = getLocale(); for (int i = 0; i < isoCountries.length; i++) { Locale tmpLocale = new Locale("en", isoCountries[i]); final String iso = tmpLocale.getCountry(); final String country = tmpLocale.getDisplayCountry(userLocale); if (StringUtils.isNotEmpty(iso) && StringUtils.isNotEmpty(country)) { countryList.add(new Option(iso, country)); } } if (isRequired() && optionList.isEmpty()) { add(Option.EMPTY_OPTION); } addAll(countryList); }
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) *///w w w . j av a2s .c om 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.orcid.frontend.web.util.LanguagesMap.java
/** * Returns the language translated in the given user locale * //from w ww. j a va 2s .c o m * @param locale * @param userLocal * * @return The language translated to the given locale. * */ @Cacheable(value = "languages-map", key = "#locale.toString() + '-' + #userLocale.toString()") public String buildLanguageValue(Locale locale, Locale userLocale) { if (userLocale != null && userLocale.getLanguage().equals("xx")) { return X; } String variant = locale.getVariant(); String displayVariant = locale.getDisplayVariant(userLocale); String language = WordUtils.capitalize(locale.getDisplayLanguage(userLocale)); if (StringUtils.isEmpty(variant)) if (StringUtils.isEmpty(locale.getDisplayCountry(userLocale))) return language; else return language + " (" + locale.getDisplayCountry(userLocale) + ')'; else if (StringUtils.isEmpty(locale.getDisplayCountry(userLocale))) return language + ' ' + displayVariant; else return language + ' ' + displayVariant + " (" + locale.getDisplayCountry(userLocale) + ')'; }
From source file:countries.ListCountry.java
public void getListOfCountries() { int supportedLocale = 0, nonSupportedLocale = 0; for (String countryCode : getISOCountries()) { Locale locale = null; if (!languagesOfCountries.containsKey(countryCode)) { locale = new Locale("", countryCode); nonSupportedLocale++;/*from w w w.j a v a 2 s .c o m*/ } else { // create a Locale with own country's languages locale = new Locale(languagesOfCountries.get(countryCode), countryCode); supportedLocale++; } out.printf("Country Code: %1$2s, Name: %2$-45s %3$-45s %4$-45s Languages: %5$10s\n", locale.getCountry(), locale.getDisplayCountry(ENGLISH), parens(locale.getDisplayCountry(FRENCH)), parens(locale.getDisplayCountry(locale)), locale.getDisplayLanguage()); } out.println("nonSupportedLocale: " + nonSupportedLocale); out.println("supportedLocale: " + supportedLocale); }
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 a 2s.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:org.sakaiproject.util.ResourceLoader.java
/** ** Return a locale's display Name//w ww . java 2 s.co m ** ** @return String used to display Locale ** ** @author Jean-Francois Leveque (Universite Pierre et Marie Curie - Paris 6) **/ public String getLocaleDisplayName(Locale loc) { Locale preferedLoc = getLocale(); StringBuilder displayName = new StringBuilder(loc.getDisplayLanguage(loc)); if (StringUtils.isNotBlank(loc.getDisplayCountry(loc))) { displayName.append(" - ").append(loc.getDisplayCountry(loc)); } if (StringUtils.isNotBlank(loc.getVariant())) { displayName.append(" (").append(loc.getDisplayVariant(loc)).append(")"); } displayName.append(" [").append(loc.toString()).append("] "); displayName.append(loc.getDisplayLanguage(preferedLoc)); if (StringUtils.isNotBlank(loc.getDisplayCountry(preferedLoc))) { displayName.append(" - ").append(loc.getDisplayCountry(preferedLoc)); } return displayName.toString(); }
From source file:com.globalsight.everest.projecthandler.MachineTranslateAdapter.java
private String getLanguagePairNameForProMt(Locale p_sourceLocale, Locale p_targetLocale) { if (p_sourceLocale == null || p_targetLocale == null) { return null; }//from w w w .ja v a 2 s .c o m String srcLang = p_sourceLocale.getDisplayLanguage(Locale.ENGLISH); String srcCountry = p_sourceLocale.getDisplayCountry(Locale.ENGLISH); if ("Chinese".equals(srcLang) && "China".equals(srcCountry)) { srcLang = "Chinese (Simplified)"; } String trgLang = p_targetLocale.getDisplayLanguage(Locale.ENGLISH); String trgCountry = p_targetLocale.getDisplayCountry(Locale.ENGLISH); if ("Chinese".equals(trgLang) && "China".equals(trgCountry)) { trgLang = "Chinese (Simplified)"; } return (srcLang + "-" + trgLang); }