List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:org.sonar.plsqlopen.CustomAnnotationBasedRulesDefinition.java
public static String getLocalizedFolderName(String baseName, Locale locale) { ResourceBundle.Control control = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT); String path = control.toBundleName(baseName, locale); URL url = CustomAnnotationBasedRulesDefinition.class.getResource(path); if (url == null) { Locale localeWithoutCountry = locale.getCountry() == null ? locale : new Locale(locale.getLanguage()); path = control.toBundleName(baseName, localeWithoutCountry); url = CustomAnnotationBasedRulesDefinition.class.getResource(path); if (url == null) { path = baseName;/*from w w w. j a va 2s . c om*/ CustomAnnotationBasedRulesDefinition.class.getResource(path); } } return path; }
From source file:Main.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// w w w . j a v a 2 s . co m * * @param locale The locale. * @return a list of postfixes to add to filenames. * @since 2.1.0 */ public static List<String> calculatePostfixes(Locale locale) { final List<String> result = new ArrayList<String>(); // The default configuration file must be loaded to allow correct // definition inheritance. result.add(""); if (locale == null) { return result; } 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(); 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.googlecode.psiprobe.Utils.java
public static List getNamesForLocale(String baseName, Locale locale) { List result = new ArrayList(3); String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); StringBuffer temp = new StringBuffer(baseName); if (language.length() > 0) { temp.append('_').append(language); result.add(0, temp.toString());//from ww w . j a v a2s . c o m } if (country.length() > 0) { temp.append('_').append(country); result.add(0, temp.toString()); } if (variant.length() > 0) { temp.append('_').append(variant); result.add(0, temp.toString()); } return result; }
From source file:com.android.mms.service.HttpUtils.java
private static void addLocaleToHttpAcceptLanguage(StringBuilder builder, Locale locale) { final String language = convertObsoleteLanguageCodeToNew(locale.getLanguage()); if (language != null) { builder.append(language);//from w w w.j av a 2s. c om final String country = locale.getCountry(); if (country != null) { builder.append("-"); builder.append(country); } } }
From source file:org.infoscoop.request.filter.GadgetFilter.java
static String getLocaleNameForLoadingI18NConstants(Locale locale) { String localeName = "en"; String language = locale.getLanguage(); String country = locale.getCountry(); if (!language.equalsIgnoreCase("ALL")) { try {/*w ww .ja v a 2s. c om*/ ResourceLoader.getContent((DATE_TIME_PATH + localeName + ".js")); localeName = language; } catch (IOException e) { // ignore } } if (!country.equalsIgnoreCase("ALL")) { try { ResourceLoader.getContent(DATE_TIME_PATH + localeName + '_' + country + ".js"); localeName += '_' + country; } catch (IOException e) { // ignore } } return localeName; }
From source file:org.jahia.services.preferences.user.UserPreferencesHelper.java
/** * Returns the preferred locale of the specified user or the first one from * the list of available locales./* ww w .j av a 2 s . co m*/ * * @param user * the user to retrieve locale preferences * @param site * the site * @return the preferred locale of the specified user or the first one from * the list of available locales */ public static Locale getPreferredLocale(JCRUserNode user, JahiaSite site) { //String propValue = getPreference("preferredLanguage", user); String propValue = user != null ? user.getPropertyAsString("preferredLanguage") : null; Locale locale = propValue != null ? LanguageCodeConverters.languageCodeToLocale(propValue) : null; if (null == locale) { // property is not set --> get list of site languages List<Locale> siteLocales = Collections.emptyList(); if (site != null) { siteLocales = site.getLanguagesAsLocales(); } if (siteLocales == null || siteLocales.size() == 0) { return JCRSessionFactory.getInstance().getCurrentLocale() != null ? JCRSessionFactory.getInstance().getCurrentLocale() : SettingsBean.getInstance().getDefaultLocale(); } List<Locale> availableBundleLocales = LanguageCodeConverters.getAvailableBundleLocales(); for (Locale siteLocale : siteLocales) { if (availableBundleLocales.contains(siteLocale)) { // this one is available locale = siteLocale; break; } else if (StringUtils.isNotEmpty(siteLocale.getCountry())) { Locale languageOnlyLocale = new Locale(siteLocale.getLanguage()); if (availableBundleLocales.contains(languageOnlyLocale)) { // get language without the country locale = new Locale(siteLocale.getLanguage()); break; } } } if (null == locale) { locale = availableBundleLocales.get(0); } } return locale; }
From source file:org.pentaho.di.i18n.GlobalMessageUtil.java
/** * Returns a string corresponding to the locale (Example: "en", "en_US"). * * @param locale The {@link Locale} whose string representation it being returned * @return a string corresponding to the locale (Example: "en", "en_US"). */// w ww . j av a 2 s.c om protected static String getLocaleString(Locale locale) { final StringBuilder localeString = new StringBuilder(); if (locale != null && !StringUtils.isBlank(locale.getLanguage())) { if (!StringUtils.isBlank(locale.getCountry())) { // force language to be lower case and country to be upper case localeString.append(locale.getLanguage().toLowerCase()).append('_') .append(locale.getCountry().toUpperCase()); } else { // force language to be lower case localeString.append(locale.getLanguage().toLowerCase()); } } return localeString.toString(); }
From source file:Main.java
/** * @param context//from w w w . jav a2 s . c o m * if null, use the default format (Mozilla/5.0 (Linux; U; * Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 * %sSafari/534.30). * @return */ public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class<?> sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase()); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase()); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:Main.java
/** * @param context if null, use the default format * (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30). * @return/*ww w. j av a2 s .c o m*/ */ public static String getUserAgent(Context context) { String webUserAgent = null; if (context != null) { try { Class sysResCls = Class.forName("com.android.internal.R$string"); Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent"); Integer resId = (Integer) webUserAgentField.get(null); webUserAgent = context.getString(resId); } catch (Throwable ignored) { } } if (TextUtils.isEmpty(webUserAgent)) { webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1"; } Locale locale = Locale.getDefault(); StringBuffer buffer = new StringBuffer(); // Add version final String version = Build.VERSION.RELEASE; if (version.length() > 0) { buffer.append(version); } else { // default to "1.0" buffer.append("1.0"); } buffer.append("; "); final String language = locale.getLanguage(); if (language != null) { buffer.append(language.toLowerCase()); final String country = locale.getCountry(); if (country != null) { buffer.append("-"); buffer.append(country.toLowerCase()); } } else { // default to "en" buffer.append("en"); } // add the model for the release build if ("REL".equals(Build.VERSION.CODENAME)) { final String model = Build.MODEL; if (model.length() > 0) { buffer.append("; "); buffer.append(model); } } final String id = Build.ID; if (id.length() > 0) { buffer.append(" Build/"); buffer.append(id); } return String.format(webUserAgent, buffer, "Mobile "); }
From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java
/** * Get the locale of the portal or the one setted into the configuration files * @return locale for message resolution *//* w ww . ja v a2 s . c o m*/ public static Locale getLocaleForMessage() { logger.info("IN"); Locale locale = null; Locale portalLocale; try { portalLocale = PortletAccess.getPortalLocale(); if (portalLocale == null) { logger.error("Portal locale not found by PortletAccess.getPortalLocale() method"); } else { logger.debug("Portal locale read succesfully: [" + portalLocale.getLanguage() + "," + portalLocale.getCountry() + "]"); } if (isLocaleSupported(portalLocale)) { logger.debug("Portal locale [" + portalLocale.getLanguage() + "," + portalLocale.getCountry() + "] is supported by SpagoBI"); locale = portalLocale; } else { logger.warn("Portal locale [" + portalLocale.getLanguage() + "," + portalLocale.getCountry() + "] is not supported by SpagoBI"); locale = GeneralUtilities.getDefaultLocale(); logger.debug( "Default locale [" + locale.getLanguage() + "," + locale.getCountry() + "] will be used"); } } catch (Exception e) { logger.error("Error while getting portal locale", e); } logger.info("OUT"); return locale; }