List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:Main.java
public static String getCountry(Context ctx) { TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); Locale locale = Locale.getDefault(); return tm.getSimState() == TelephonyManager.SIM_STATE_READY ? tm.getSimCountryIso().toLowerCase(Locale.getDefault()) : locale.getCountry().toLowerCase(locale); }
From source file:org.infoscoop.util.I18NUtil.java
public static Map getResourceMap(String type, Locale locale) { String country = locale.getCountry(); String lang = locale.getLanguage(); Map resMap = null;/*from w w w. ja v a2 s.c om*/ I18NDAO i18NDAO = I18NDAO.newInstance(); String lastmodified = i18NDAO.getLastmodified(type); String key = type + "_" + country + "_" + lang; ResourceMap rm = (ResourceMap) i18nMap.get(key); if (rm != null) { String current = rm.getLastmodified(); if (lastmodified == null || (current != null && current.equals(lastmodified))) { resMap = rm.getResMap(); } } if (resMap == null) { resMap = I18NService.getHandle().getResourceMap(type, country, lang); i18nMap.put(key, new ResourceMap(lastmodified, resMap)); } return resMap; }
From source file:no.kantega.commons.util.LocaleLabels.java
public static Enumeration getKeys(String bundleName, Locale locale) { String loc = locale.getLanguage() + "_" + locale.getCountry(); if (isNotBlank(locale.getVariant())) { loc += "_" + locale.getVariant(); }// w ww .ja va 2s. c o m PropertyResourceBundle bundle = getBundle(bundleName, loc); if (bundle == null) { return null; } return bundle.getKeys(); }
From source file:org.eclipse.wb.internal.core.nls.ui.FlagImagesRepository.java
/** * @return the {@link Image} of flag for given {@link Locale}. */// w w w. j a v a2 s . co m public static Image getFlagImage(Locale locale) { init(); String localeCountry = locale.getCountry(); String localeLanguage = locale.getLanguage(); // if locale has no assosiated country set, try to find the locale with the same language but with the country set if (localeCountry.length() == 0) { // special cases if (localeLanguage.equals("ar")) { localeCountry = "AE"; } else if (localeLanguage.equals("zh")) { localeCountry = "CN"; } else if (localeLanguage.equals("en")) { localeCountry = "US"; } else { // try to guess String localeCountryCandidate = ""; for (int i = 0; i < m_locales.length; i++) { Locale lookupLocale = m_locales[i]; String lookupLanguage = lookupLocale.getLanguage(); if (lookupLanguage.equals(localeLanguage)) { if (lookupLocale.getCountry().length() != 0) { localeCountryCandidate = lookupLocale.getCountry(); if (localeCountryCandidate.equalsIgnoreCase(lookupLanguage)) { localeCountry = localeCountryCandidate; break; } } } } if (localeCountry.length() == 0) { localeCountry = localeCountryCandidate; } } } // Image flagImage = m_countriesFlags.get(localeCountry); if (flagImage == null) { try { String flagFileName = null; if (localeCountry.equalsIgnoreCase("YU")) { localeCountry = "CS"; // use Serbia and Montenegro } if (StringUtils.isEmpty(localeCountry)) { return null; } flagFileName = localeCountry.toLowerCase() + ".png"; flagImage = DesignerPlugin.getImage("nls/flags/" + flagFileName); m_countriesFlags.put(localeCountry, flagImage); } catch (Throwable e) { return null; } } return flagImage; }
From source file:com.revolsys.ui.html.domain.PhoneNumber.java
/** * Format the phone number using the National format specification defined for * the Locale. If the phone number does not match the specification for that * locale the first few digits of the phone number will be used to lookup a * matching country and formatted using that locale, if that fails the * unformatted phone number will be returned. * * @param phoneNumber The normalized phone number to format. * @param locale The Locale the phone number should be formatted for. * @return The formatted phone number./*from w w w . jav a 2 s .c o m*/ */ public static String format(final String phoneNumber, final Locale locale) { return format(phoneNumber, Country.getCountry(locale.getCountry()), false); }
From source file:Main.java
private static String i(Context context) { if (h == null) { String s = (new WebView(context)).getSettings().getUserAgentString(); if (s == null || s.length() == 0 || s.equals("Java0")) { String s1 = System.getProperty("os.name", "Linux"); String s2 = (new StringBuilder()).append("Android ").append(android.os.Build.VERSION.RELEASE) .toString();// ww w .j a va2 s .co m Locale locale = Locale.getDefault(); String s3 = locale.getLanguage().toLowerCase(); if (s3.length() == 0) s3 = "en"; String s4 = locale.getCountry().toLowerCase(); String s5; String s6; if (s4.length() > 0) s5 = (new StringBuilder()).append(s3).append("-").append(s4).toString(); else s5 = s3; s6 = (new StringBuilder()).append(Build.MODEL).append(" Build/").append(Build.ID).toString(); s = (new StringBuilder()).append("Mozilla/5.0 (").append(s1).append("; U; ").append(s2).append("; ") .append(s5).append("; ").append(s6).append(") AppleWebKit/0.0 (KHTML, like ") .append("Gecko) Version/0.0 Mobile Safari/0.0").toString(); } h = (new StringBuilder()).append(s).append(" (Mobile; ").append("afma-sdk-a-v").append("4.1.0") .append(")").toString(); } return h; }
From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.properties.ui.wizards.NewPropertiesContentErrorLibraryWizardPage.java
private static String toString(Locale locale) { final String language = locale.getLanguage(); final String country = locale.getCountry(); final String variant = locale.getVariant(); boolean l = language.length() != 0; boolean c = country.length() != 0; boolean v = variant.length() != 0; StringBuffer result = new StringBuffer(language); /*/*from w w w . ja va 2s.c om*/ * ibm@118171 start The Serbian locale does not obey the convention of * language_country_variant, so we have to special-case it here pending * a properly thought-out fix */ if ((language.equals("sh") || language.equals("sr")) && (country.equals("RS")) && (variant.equals("Latn") || variant.equals("Cyrl"))) { return (language + "-" + variant + "-" + country); } /* ibm@118171 end */ if (c || (l && v)) { result.append('-').append(country); // This may just append '-' } if (v && (l || c)) { result.append('-').append(variant); } return result.toString(); }
From source file:Main.java
/** * Converte a Locale object to an xmlLang String * @param locale/*from w ww.ja v a 2 s . c om*/ * @return String of the form <locale.getLanguage()>-<locale.getCountry()> */ private static String localeToXmlLang(Locale locale) { if (locale == null) { return Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry(); } String lang = locale.getLanguage(); String countryCode = locale.getCountry(); if (countryCode == null || countryCode.length() == 0) { return lang; } else { return new String(lang + "-" + countryCode); } }
From source file:no.kantega.commons.util.LocaleLabels.java
private static String getLocaleName(Locale locale) { StringBuilder loc = new StringBuilder(locale.getLanguage()); if (isNotBlank(locale.getCountry())) { loc.append("_").append(locale.getCountry()); }/*from w ww . j a v a2 s. c o m*/ if (isNotBlank(locale.getVariant())) { loc.append("_").append(locale.getVariant()); } return loc.toString(); }
From source file:Main.java
public static String getRegionCode(Context context) { Locale locale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { locale = context.getResources().getConfiguration().getLocales().get(0); } else {// ww w . ja v a 2 s . c o m locale = context.getResources().getConfiguration().locale; } return locale.getCountry(); }