List of usage examples for java.util Locale getDisplayCountry
public String getDisplayCountry(Locale inLocale)
From source file:Main.java
public static void main(String[] args) { Locale locale = new Locale("ENGLISH", "US"); System.out.println("Locale:" + locale); //display name - result is based on inLocale System.out.println("Display Name:" + locale.getDisplayCountry(new Locale("GERMAN", "GERMANY"))); }
From source file:Main.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:com.hack23.cia.service.impl.ConfigurationManagerImpl.java
/** * Gets the supported locales language data. * * @return the supported locales language data */// w w w. j av a 2 s .c om private static List<LanguageData> getSupportedLocalesLanguageData() { final List<LanguageData> languages = new ArrayList<>(); for (final Locale locale : SimpleDateFormat.getAvailableLocales()) { if (locale.getDisplayCountry(Locale.ENGLISH).length() == 0 && !StringUtils.isEmpty(locale.toString()) && locale.toString().trim().length() == EXPECTED_LOCALE_LENGTH) { languages.add(new LanguageData().withCreatedDate(new Date()).withLanguageCode(locale.toString()) .withLanguageName(locale.getDisplayName(Locale.ENGLISH)).withLanguageEnabled(false)); } } return languages; }
From source file:eu.eubrazilcc.lvl.core.geocoding.GeocodingHelper.java
/** * Converts a Java {@link Locale} to geographic coordinates. * @param locale - the locale to be converted * @return a {@link Point} that represents a geospatial location in GeoJSON format using WGS84 * coordinate reference system (CRS). *//*from w w w.jav a 2 s . c om*/ public static final Optional<Point> geocode(final Locale locale) { checkArgument(locale != null, "Uninitialized or invalid locale"); return geocode(locale.getDisplayCountry(ENGLISH)); }
From source file:org.openestate.io.core.LocaleUtils.java
/** * Translate a country name into another language. * * @param country//from w w w . j a v a2s .c o m * country name * * @param language * language to translate * * @return * translated country name or null, if no translation was found */ public static String translateCountryName(String country, Locale language) { country = StringUtils.trimToNull(country); if (country == null) return null; for (String iso2Code : Locale.getISOCountries()) { Locale countryLocale = new Locale(iso2Code, iso2Code); for (Locale translationLocale : LocaleUtils.availableLocaleList()) { String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale)); if (name != null && name.equalsIgnoreCase(country)) { name = StringUtils.trimToNull(countryLocale.getDisplayCountry(language)); if (name != null) return name; } } } return null; }
From source file:org.openestate.io.core.LocaleUtils.java
/** * Return an ISO-2 country code from a country name. * * @param country/*from ww w. ja va 2s . c o m*/ * country name * * @return * ISO-2 country code or null, if no code was found */ public static String getCountryISO2(String country) { country = StringUtils.trimToNull(country); if (country == null) return null; if (country.length() == 2) return country; String[] iso2Codes = Locale.getISOCountries(); if (country.length() == 3) { String iso2Code = LocaleUtils.getCountryISO2FromISO3(country); if (iso2Code != null) return iso2Code; } for (String iso2Code : iso2Codes) { Locale countryLocale = new Locale(iso2Code, iso2Code); for (Locale translationLocale : LocaleUtils.availableLocaleList()) { String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale)); if (name != null && name.equalsIgnoreCase(country)) return iso2Code; } } return null; }
From source file:org.jahia.ajax.gwt.helper.LanguageHelper.java
/** * Get icon style depending and the selected language * * * @param locale//from w ww . j a v a2 s . c o m * @return */ public static String getLangIcon(String contextPath, Locale locale) { if ("".equals(locale.getCountry())) return contextPath + "/css/images/flags/" + locale.getLanguage().toLowerCase() + "_on.png"; else return contextPath + "/css/images/flags/plain/flag_" + Patterns.SPACE.matcher(locale.getDisplayCountry(Locale.ENGLISH).toLowerCase()).replaceAll("_") + ".png"; }
From source file:org.openestate.io.core.LocaleUtils.java
/** * Return an ISO-3 country code from a country name. * * @param country//from w w w. j a v a 2s . c om * country name * * @return * ISO-3 country code or null, if no code was found */ public static String getCountryISO3(String country) { country = StringUtils.trimToNull(country); if (country == null) return null; if (country.length() == 3) return country; String[] iso2Codes = Locale.getISOCountries(); if (country.length() == 2) { String iso3code = LocaleUtils.getCountryISO3FromISO2(country); if (iso3code != null) return iso3code; } for (String iso2Code : iso2Codes) { Locale countryLocale = new Locale(iso2Code, iso2Code); String iso3Code = StringUtils.trimToNull(countryLocale.getISO3Country()); if (iso3Code == null) continue; for (Locale translationLocale : LocaleUtils.availableLocaleList()) { String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale)); if (name != null && name.equalsIgnoreCase(country)) return iso3Code; } } return null; }
From source file:org.jahia.taglibs.functions.Functions.java
public static String getLangIcon(Locale localeToDisplay) { if ("".equals(localeToDisplay.getCountry())) return "flag_" + localeToDisplay.getLanguage().toLowerCase() + "_on"; else//from w w w . j av a 2 s. c om return "flag_" + Patterns.SPACE.matcher(localeToDisplay.getDisplayCountry(Locale.ENGLISH).toLowerCase()) .replaceAll("_"); }
From source file:org.primeframework.mvc.control.form.CountrySelect.java
/** * Adds the countries Map and then calls super. *///w w w. j a v a2 s . 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(); }