List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:org.gatein.api.management.Utils.java
public static void populate(String fieldName, Locale locale, ModelObject model) { if (locale == null) { model.set(fieldName, (String) null); return;/* www . j a v a 2 s. com*/ } String localeString = locale.getLanguage(); if (localeString == null) { throw new RuntimeException("Language was null for locale " + locale); } String country = locale.getCountry(); if (country != null && country.length() > 0) { localeString += "-" + country.toUpperCase(); } model.set(fieldName, localeString); }
From source file:org.itracker.core.resources.ITrackerResources.java
private static String handleMissingResourceException(final MissingResourceException ex, final String key, final Locale locale) { logger.warn("no value while retrieving translation key '{}' for locale {}", key, locale); Locale l = locale; if (null == l) { l = getLocale(getDefaultLocale()); }/* ww w.j a v a 2 s . c o m*/ if (StringUtils.isNotEmpty(l.getCountry())) { l = new Locale(l.getLanguage()); } else if (StringUtils.isNotEmpty(l.getLanguage())) { l = new Locale(""); } if (l != locale) { logger.debug("resolving {}from parent bundle ()", key, l); return getString(key, l); } throw ex; }
From source file:org.pentaho.platform.util.xml.XmlHelper.java
public static InputStream getLocalizedFile(final String fullPath, final Locale locale, final IDocumentResourceLoader loader) { String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); // File file = new File(fullPath); String fileName = fullPath;//from w w w .j ava 2 s . co m int dotIndex = fileName.indexOf('.'); String baseName = dotIndex == -1 ? fileName : fileName.substring(0, dotIndex); // These two lines fix an // index out // of bounds String extension = dotIndex == -1 ? "" : fileName.substring(dotIndex); // Exception that occurs when a filename has no extension //$NON-NLS-1$ InputStream in = null; try { if (!variant.equals("")) { //$NON-NLS-1$ in = loader.loadXsl(baseName + "_" + language + "_" + country + "_" + variant + extension); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } if (in == null) { in = loader.loadXsl(baseName + "_" + language + "_" + country + extension); //$NON-NLS-1$//$NON-NLS-2$ } if (in == null) { in = loader.loadXsl(baseName + "_" + language + extension); //$NON-NLS-1$ } if (in == null) { in = loader.loadXsl(baseName + extension); } } catch (Exception e) { Logger.error(XmlHelper.class.getName(), "Error loading localized file: " + fullPath); //$NON-NLS-1$ } return in; }
From source file:org.atricore.idbus.bundles.apache.tiles.OsgiDefinitionsFactory.java
/** * Calculate the postfixes along the search path from the base bundle to the * bundle specified by baseName and locale. * Method copied from java.util.ResourceBundle * * @param locale the locale/*from ww w . j av a2 s . com*/ * @return a list of */ protected static List<String> calculatePostfixes(Locale locale) { final List<String> result = new ArrayList<String>(); final String language = locale.getLanguage(); final int languageLength = language.length(); final String country = locale.getCountry(); final int countryLength = country.length(); final String variant = locale.getVariant(); final int variantLength = variant.length(); // The default configuration file must be loaded to allow correct // definition inheritance. result.add(""); if (languageLength + countryLength + variantLength == 0) { //The locale is "", "", "". return result; } final StringBuffer temp = new StringBuffer(); temp.append('_'); temp.append(language); if (languageLength > 0) { result.add(temp.toString()); } if (countryLength + variantLength == 0) { return result; } temp.append('_'); temp.append(country); if (countryLength > 0) { result.add(temp.toString()); } if (variantLength == 0) { return result; } else { temp.append('_'); temp.append(variant); result.add(temp.toString()); return result; } }
From source file:com.google.android.gm.ay.java
private static Uri y(final Context context, String replace) { if (replace.contains("%locale%")) { final Locale default1 = Locale.getDefault(); replace = replace.replace("%locale%", default1.getLanguage() + "_" + default1.getCountry().toLowerCase()); }/*from w w w . j a va 2 s .com*/ Uri$Builder uri$Builder = Uri.parse(replace).buildUpon(); final String ag = aG(context); if (ag != null) { uri$Builder = uri$Builder.appendQueryParameter("version", ag); } int n; if (ay.aZh.contains(context.getResources().getConfiguration().mcc) || bj(context)) { n = 1; } else { n = 0; } String s; if (n != 0) { s = "1"; } else { s = "0"; } return uri$Builder.appendQueryParameter("googleMail", s).build(); }
From source file:org.eclipse.smarthome.binding.weatherunderground.handler.WeatherUndergroundHandler.java
/** * Get the WU code associated to a language * * @param locale the locale settings with language and country * @return the associated WU code or an empty string if not found *//* ww w .j a v a 2 s .c o m*/ public static String getCodeFromLanguage(Locale locale) { String key = locale.getLanguage() + "-" + locale.getCountry(); String language = StringUtils.trimToEmpty(LANG_COUNTRY_TO_WU_CODES.get(key)); if (language.isEmpty()) { language = StringUtils.trimToEmpty(LANG_ISO_TO_WU_CODES.get(locale.getLanguage().toUpperCase())); } return language; }
From source file:com.google.android.gm.ay.java
public static void a(final Activity activity, final Account account, final String s) { final Uri build = Uri .parse(c.a(activity.getContentResolver(), "gmail_context_sensitive_help_url", "http://support.google.com/mail")) .buildUpon().appendPath("topic").appendPath(activity.getString(2131297018)).build(); final Locale default1 = Locale.getDefault(); final Uri build2 = build.buildUpon() .appendQueryParameter("hl", default1.getLanguage() + "_" + default1.getCountry().toLowerCase()) .build();/*w w w. j a va 2 s.c o m*/ final GoogleHelp a = GoogleHelp.gi(s).L(build2).h(GoogleHelp.j(activity)).z(g((Context) activity, account)) .a(2131558417, activity.getString(2131296702), h((Context) activity, build2)) .a(2131558418, activity.getString(2131297062), h((Context) activity, Uri.parse(c.a(activity.getContentResolver(), "gmail_privacy_policy_url", "https://www.google.com/policies/privacy/")))) .a(2131558419, activity.getString(2131297061), new Intent((Context) activity, (Class) LicenseActivity.class)) .a(2131558420, activity.getString(2131297063), h((Context) activity, Uri.parse(c.a(activity.getContentResolver(), "gmail_terms_of_service_url", "https://www.google.com/policies/terms/")))); if (account != null) { a.d(account.uf()); } new a(activity).e(a.QA()); }
From source file:org.jahia.utils.LanguageCodeConverters.java
public static Locale resolveLocaleForGuest(HttpServletRequest request) { List<Locale> availableBundleLocales = getAvailableBundleLocales(); Enumeration<Locale> browserLocales = request.getLocales(); Locale resolvedLocale = availableBundleLocales != null && !availableBundleLocales.isEmpty() ? availableBundleLocales.get(0) : Locale.ENGLISH;// www . j ava 2 s . co m while (browserLocales != null && browserLocales.hasMoreElements()) { Locale candidate = browserLocales.nextElement(); if (candidate != null) { if (availableBundleLocales.contains(candidate)) { resolvedLocale = candidate; break; } else if (StringUtils.isNotEmpty(candidate.getCountry()) && availableBundleLocales.contains(new Locale(candidate.getLanguage()))) { resolvedLocale = new Locale(candidate.getLanguage()); break; } } } return resolvedLocale; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.candidacies.RefactoredIndividualCandidacyProcessPublicDA.java
static private String readCountryCode(final Locale locale) { String country = locale.getCountry(); String language = locale.getLanguage(); String result = null;/*from w ww . j av a2s .c o m*/ if (!StringUtils.isEmpty(country)) { result = country.toUpperCase(); } else if (!StringUtils.isEmpty(language)) { result = language.toUpperCase(); } if (!StringUtils.isEmpty(result)) { return result; } return "PT"; }
From source file:org.tinygroup.template.rumtime.TemplateUtil.java
/** * ?/*from w w w . j ava2 s . c om*/ * @param path * @param locale * @return */ public static String getLocalePath(String path, Locale locale) { if (locale != null) { int pos = path.lastIndexOf("."); String localePath = path.substring(0, pos) + "_" + locale.getLanguage() + "_" + locale.getCountry() + path.substring(pos); return localePath; } return path; }