List of usage examples for java.util Locale toString
@Override public final String toString()
Locale
object, consisting of language, country, variant, script, and extensions as below: language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensionsLanguage is always lower case, country is always upper case, script is always title case, and extensions are always lower case.
From source file:com.iisigroup.cap.mvc.i18n.MessageBundleScriptCreator.java
/** * ? i18n /*from w ww . j av a2s . co m*/ * * @param i18nPath * i18nPath * @return Properties */ private static Properties loadProperties(String i18nPath) { Properties prop = new Properties(); Locale locale = null; try { locale = CapSecurityContext.getLocale(); if (locale == null) { locale = Locale.getDefault(); } } catch (Exception e) { locale = Locale.getDefault(); } String i18nFile = null; InputStream is = null; try { i18nFile = new StringBuffer("classpath:/i18n/").append(i18nPath).append("_").append(locale.toString()) .append(".properties").toString(); Resource rs = CapAppContext.getApplicationContext().getResource(i18nFile); if (rs != null) { is = rs.getInputStream(); prop.load(is); } else { i18nFile = new StringBuffer("classpath:/i18n/").append(i18nPath).append("_").append(".properties") .toString(); rs = CapAppContext.getApplicationContext().getResource(i18nFile); if (rs != null) { is = rs.getInputStream(); prop.load(is); } } } catch (Exception e) { LOGGER.error("can't load " + i18nPath); } finally { IOUtils.closeQuietly(is); } return prop; }
From source file:org.itracker.core.resources.ITrackerResources.java
public static String getLocaleDN(Locale locale, Locale displayLocale) { if (null == displayLocale) { return getLocaleNativeName(displayLocale); }//from w w w .j a v a 2 s . co m return getLocaleDN(locale.toString(), displayLocale); }
From source file:org.apache.manifoldcf.core.i18n.Messages.java
/** Obtain a resource bundle given a class, bundle name, and locale. *@return null if the resource bundle could not be found. *//*from ww w .j a v a 2 s . co m*/ public static ResourceBundle getResourceBundle(Class clazz, String bundleName, Locale locale) { ResourceBundle resources; ClassLoader classLoader = clazz.getClassLoader(); try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e) { complainMissingBundle("Missing resource bundle '" + bundleName + "' for locale '" + locale.toString() + "': " + e.getMessage() + "; trying " + locale.getLanguage(), e, bundleName, locale); // Try plain language next locale = new Locale(locale.getLanguage()); try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e2) { // Use English if we don't have a bundle for the current locale complainMissingBundle("Missing resource bundle '" + bundleName + "' for locale '" + locale.toString() + "': " + e2.getMessage() + "; trying en_US", e2, bundleName, locale); locale = Locale.US; try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e3) { complainMissingBundle("No backup en_US bundle found! " + e3.getMessage(), e3, bundleName, locale); locale = new Locale(locale.getLanguage()); try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e4) { complainMissingBundle("No backup en bundle found! " + e4.getMessage(), e4, bundleName, locale); return null; } } } } return resources; }
From source file:org.apache.manifoldcf.core.i18n.Messages.java
/** Read a resource as an input stream, given a class, path, locale, and resource key. *//* w w w. j a v a 2 s. c om*/ public static InputStream getResourceAsStream(Class classInstance, String pathName, Locale originalLocale, String resourceKey) throws ManifoldCFException { Locale locale = originalLocale; InputStream is = classInstance.getResourceAsStream(localizeResourceName(pathName, resourceKey, locale)); if (is == null) { complainMissingResource( "No resource in path '" + pathName + "' named '" + resourceKey + "' found for locale '" + locale.toString() + "'", new Exception("Resource not found"), pathName, locale, resourceKey); locale = new Locale(locale.getLanguage()); is = classInstance.getResourceAsStream(localizeResourceName(pathName, resourceKey, locale)); if (is == null) { complainMissingResource( "No resource in path '" + pathName + "' named '" + resourceKey + "' found for locale '" + locale.toString() + "'", new Exception("Resource not found"), pathName, locale, resourceKey); locale = Locale.US; is = classInstance.getResourceAsStream(localizeResourceName(pathName, resourceKey, locale)); if (is == null) { complainMissingResource( "No resource in path '" + pathName + "' named '" + resourceKey + "' found for locale '" + locale.toString() + "'", new Exception("Resource not found"), pathName, locale, resourceKey); locale = new Locale(locale.getLanguage()); is = classInstance.getResourceAsStream(localizeResourceName(pathName, resourceKey, locale)); if (is == null) { complainMissingResource( "No resource in path '" + pathName + "' named '" + resourceKey + "' found for locale '" + locale.toString() + "'", new Exception("Resource not found"), pathName, locale, resourceKey); is = classInstance.getResourceAsStream(localizeResourceName(pathName, resourceKey, null)); if (is == null) throw new ManifoldCFException( "No matching language resource in path '" + pathName + "' named '" + resourceKey + "' found for locale '" + originalLocale.toString() + "'"); } } } } return is; }
From source file:org.agiso.core.i18n.util.I18nUtils.java
public static String getLocaleLanguageTag(Locale locale) { if (METHOD_TO_LANGUAGE_TAG != null) try {// w w w . j a v a 2s . c o m return (String) METHOD_TO_LANGUAGE_TAG.invoke(locale); } catch (Exception e) { } return locale.toString(); }
From source file:org.itracker.core.resources.ITrackerResources.java
public static void putBundle(Locale locale, ResourceBundle bundle) { if (locale != null && bundle != null) { synchronized (bundleLock) { languages.put(locale, bundle); String localeString = locale.toString(); if (localeString.length() == 5) { localeString = localeString.substring(0, 2) + "_" + localeString.substring(3).toUpperCase(); }//w ww .j a v a 2 s. c o m locales.put(localeString, locale); } } }
From source file:org.dspace.core.I18nUtil.java
/** * Gets the appropriate supported Locale according for a given Locale If * no appropriate supported locale is found, the DEFAULTLOCALE is used * * @param locale/*from w w w. ja va2 s . c o m*/ * Locale to find the corresponding Locale * @return supportedLocale * Locale for session according to locales supported by this DSpace instance as set in dspace.cfg */ public static Locale getSupportedLocale(Locale locale) { Locale[] availableLocales = getSupportedLocales(); boolean isSupported = false; Locale supportedLocale = null; String testLocale = ""; if (availableLocales == null) { supportedLocale = DEFAULTLOCALE; } else { if (!locale.getVariant().equals("")) { testLocale = locale.toString(); for (int i = 0; i < availableLocales.length; i++) { if (testLocale.equalsIgnoreCase(availableLocales[i].toString())) { isSupported = true; supportedLocale = availableLocales[i]; } } } if (!(isSupported && locale.getCountry().equals(""))) { testLocale = locale.getLanguage() + "_" + locale.getCountry(); for (int i = 0; i < availableLocales.length; i++) { if (testLocale.equalsIgnoreCase(availableLocales[i].toString())) { isSupported = true; supportedLocale = availableLocales[i]; } } } if (!isSupported) { testLocale = locale.getLanguage(); for (int i = 0; i < availableLocales.length; i++) { if (testLocale.equalsIgnoreCase(availableLocales[i].toString())) { isSupported = true; supportedLocale = availableLocales[i]; } } } if (!isSupported) { supportedLocale = DEFAULTLOCALE; } } return supportedLocale; }
From source file:com.aurel.track.admin.customize.localize.LocalizeBL.java
/** * Set the same value also in the TLocalizedResources table with null (or for now "" (mandatory)) locale. * The localization will be loaded from this table, and if not found, * from the localized property files, and if not found there from the "native" table. * The problem is that the correspondence is made through the key (which do not change) instead of values * and localized property files use the same key for existing entries and then the * renamed label is not visible because the localized property files have priority over those from the "native" table. * This intermediate step is introduced to solve the problem until this localisation * in database will be implemented also in the Web-Interface. * @param fieldName/*from ww w. j a v a 2 s.com*/ * @param primaryKey * @param label * @param locale */ public static void saveLocalizedResource(String fieldName, Integer primaryKey, String label, Locale locale) { String localeString = null; if (locale != null) { localeString = locale.toString(); } List<TLocalizedResourcesBean> localizedResources = localizedResourcesDAO .getLocalizedResourceForKey(fieldName, primaryKey, localeString); save(label, fieldName, primaryKey, localizedResources, localeString); }
From source file:org.alfresco.repo.content.filestore.SpoofedTextContentReader.java
/** * Helper to create a content URL that represents spoofed text * // w w w .ja v a2 s . c o m * @param locale the text local (must be supported by an appropriate lexicon config resource) * @param seed numerical seed to ensure repeatable sequences of random text * @param size the size (bytes) of the text to generate * @param words additional words with decreasing frequency * @return the content URL * * @throws IllegalArgumentException if the resulting URL exceeds 255 characters */ @SuppressWarnings("unchecked") public static String createContentUrl(Locale locale, long seed, long size, String... words) { if (locale == null || size < 0L) { throw new IllegalArgumentException("Locale must be supplied and size must be zero or greater."); } // Make sure that there is a text generator available SpoofedTextContentReader.getTextGenerator(locale); // Build map String url = null; try { JSONObject jsonObj = new JSONObject(); jsonObj.put(KEY_LOCALE, locale.toString()); jsonObj.put(KEY_SEED, Long.valueOf(seed).toString()); jsonObj.put(KEY_SIZE, Long.valueOf(size).toString()); JSONArray jsonWords = new JSONArray(); for (String word : words) { if (word == null) { throw new IllegalArgumentException("Words to inject into the document may not be null."); } jsonWords.add(word); } jsonObj.put(KEY_WORDS, jsonWords); url = FileContentStore.SPOOF_PROTOCOL + "://" + jsonObj.toString(); if (url.length() > 255) { throw new IllegalArgumentException( "Content URLs can be up to 255 characters. Have " + url.length() + " characters: " + url); } return url; } catch (IllegalArgumentException e) { // Let these out as they are throw e; } catch (Exception e) { throw new RuntimeException( "Unable to create content URL using " + locale + ", " + seed + ", " + size + ", " + words, e); } }
From source file:com.aurel.track.admin.customize.localize.LocalizeBL.java
/** * Gets the primary key by localized text * TODO do not get always from the database but make a cache also for the "inverse" maps * @param fieldName/* w w w . j av a 2 s. co m*/ * @param localizedText * @param locale * @return */ public static Integer getPrimaryKey(String fieldName, String localizedText, Locale locale) { String localeString = null; if (locale != null) { localeString = locale.toString(); } TLocalizedResourcesBean localizedResourcesBean = localizedResourcesDAO.getKeyForLocalizedResource(fieldName, localizedText, localeString); if (localizedResourcesBean != null) { return localizedResourcesBean.getPrimaryKeyValue(); } if (locale != null) { localizedResourcesBean = localizedResourcesDAO.getKeyForLocalizedResource(fieldName, localizedText, null); if (localizedResourcesBean != null) { return localizedResourcesBean.getPrimaryKeyValue(); } } return null; }