Package org.jivesoftware.util
Class LocaleUtils
java.lang.Object
org.jivesoftware.util.LocaleUtils
A set of methods for retrieving and converting locale specific strings and numbers.
- Author:
- Jive Software
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetLocalizedNumber(double number) Returns an internationalized String representation of the number using the default locale.static StringgetLocalizedNumber(double number, Locale locale) Returns an internationalized String representation of the number using the specified locale.static StringgetLocalizedNumber(long number) Returns an internationalized String representation of the number using the default locale.static StringgetLocalizedNumber(long number, Locale locale) Returns an internationalized String representation of the number using the specified locale.static StringgetLocalizedPluginString(String pluginName, String key) Returns an internationalized string loaded from a plugins resource bundle using the Jive Locale.static StringgetLocalizedString(String key) Returns an internationalized string loaded from a resource bundle.static StringgetLocalizedString(String key, String pluginName) Returns an internationalized string loaded from a resource bundle from the passed in plugin.static StringgetLocalizedString(String key, String pluginName, List arguments) Returns an internationalized string loaded from a resource bundle from the passed in plugin.static StringgetLocalizedString(String key, String pluginName, List<?> arguments, Locale locale, boolean fallback) Returns an internationalized string loaded from a resource bundle from the passed in plugin, using the passed in Locale.static StringgetLocalizedString(String key, List<?> arguments) Returns an internationalized string loaded from a resource bundle using the locale specified by JiveGlobals.getLocale() substituting the passed in arguments.static StringgetLocalizedString(String key, List<?> arguments, Locale locale) Returns an internationalized string loaded from a resource bundle substituting the passed in arguments.static StringgetLocalizedString(String key, Locale locale) Returns an internationalized string loaded from a resource bundle using the passed in Locale.static StringgetLocalizedString(String key, Locale locale, List arguments, ResourceBundle bundle) Returns an internationalized string loaded from a resource bundle using the passed in Locale substituting the passed in arguments.static ResourceBundlegetPluginResourceBundle(String pluginName) Retrieve theResourceBundlethat is used with this plugin.static ResourceBundlegetResourceBundle(String baseName, Locale locale) Returns the specified resource bundle, which is a properties file that aids in localization of skins.static String[][]Returns a list of all available time zone's as a String [][].static StringgetTimeZoneName(String zoneID, Locale locale) Returns the display name for a time zone.static booleanChecks if the current locale (the one specified by JiveGlobals.getLocale()) uses the 'right-to-left' text orientation.static LocalelocaleCodeToLocale(String localeCode) Converts a locale string like "en", "en_US" or "en_US_win" to a Java locale object.
-
Field Details
-
OPENFIRE_PLUGIN_NAME
- See Also:
-
-
Method Details
-
localeCodeToLocale
Converts a locale string like "en", "en_US" or "en_US_win" to a Java locale object. If the conversion fails, null is returned.- Parameters:
localeCode- the locale code for a Java locale. See theLocaleclass for more details.- Returns:
- The Java Locale that matches the locale code, or
null.
-
getTimeZoneList
Returns a list of all available time zone's as a String [][]. The first entry in each list item is the timeZoneID, and the second is the display name.The list of time zones attempts to be inclusive of all of the worlds zones while being as concise as possible. For "en" language locales the name is a friendly english name. For non-"en" language locales the standard JDK name is used for the given Locale. The GMT+/- time is also included for readability.
- Returns:
- a list of time zones, as a tuple of the zime zone ID, and its display name.
-
getTimeZoneName
Returns the display name for a time zone. The display name is the name specified by the Java TimeZone class for non-"en" locales or a friendly english name for "en", with the addition of the GMT offset for human readability.- Parameters:
zoneID- the time zone to get the name for.locale- the locale to use.- Returns:
- the display name for the time zone.
-
getResourceBundle
Returns the specified resource bundle, which is a properties file that aids in localization of skins. This method is handy since it uses the class loader that other Jive classes are loaded from (hence, it can load bundles that are stored in jive.jar).- Parameters:
baseName- the name of the resource bundle to load.locale- the desired Locale.- Returns:
- the specified resource bundle, if it exists.
-
isLocalizedTextRTL
public static boolean isLocalizedTextRTL()Checks if the current locale (the one specified by JiveGlobals.getLocale()) uses the 'right-to-left' text orientation.- Returns:
- true if the current locale uses right-to-left orientation.
-
getLocalizedString
Returns an internationalized string loaded from a resource bundle. The locale used will be the locale specified by JiveGlobals.getLocale().- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.- Returns:
- the localized string.
-
getLocalizedString
Returns an internationalized string loaded from a resource bundle using the passed in Locale. If the passed in Locale cannot be used to retrieve a localized string, the locale specified by JiveGlobals.getLocale() will be used instead.- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.locale- the locale to use for retrieving the appropriate locale-specific string.- Returns:
- the localized string.
-
getLocalizedPluginString
Returns an internationalized string loaded from a plugins resource bundle using the Jive Locale. The name of resource bundle will be the lower-case word characters of the plugin name, with an
_18nsuffix.As a special case, if the plugin name is
OPENFIRE_PLUGIN_NAMEthen the standard Openfire i18n resource bundle is used.- Parameters:
pluginName- The name of the plugin - as defined in plugin.xmlkey- The key to use for retrieving the string from the appropriate resource bundle- Returns:
- the localized string.
-
getLocalizedString
Returns an internationalized string loaded from a resource bundle using the locale specified by JiveGlobals.getLocale() substituting the passed in arguments. Substitution is handled using theMessageFormatclass.- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.arguments- a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.- Returns:
- the localized string.
-
getLocalizedString
Returns an internationalized string loaded from a resource bundle substituting the passed in arguments. Substitution is handled using theMessageFormatclass. If the passed in Locale cannot be used to retrieve a localized string, the locale specified by JiveGlobals.getLocale() will be used instead.- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.arguments- a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.locale- the locale to use for retrieving the appropriate locale-specific string.- Returns:
- the localized string.
-
getLocalizedString
Returns an internationalized string loaded from a resource bundle from the passed in plugin. If the plugin name isnull, the key will be looked up using the standard resource bundle.- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.pluginName- the name of the plugin to load the require resource bundle from.- Returns:
- the localized string.
-
getLocalizedString
Returns an internationalized string loaded from a resource bundle from the passed in plugin. If the plugin name isnull, the key will be looked up using the standard resource bundle.- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.pluginName- the name of the plugin to load the require resource bundle from.arguments- a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.- Returns:
- the localized string.
-
getLocalizedString
public static String getLocalizedString(String key, String pluginName, List<?> arguments, Locale locale, boolean fallback) Returns an internationalized string loaded from a resource bundle from the passed in plugin, using the passed in Locale. If the plugin name isnull, the key will be looked up using the standard resource bundle. If the locale isnull, the Jive Global locale will be used.- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.pluginName- the name of the plugin to load the require resource bundle from.arguments- a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.locale- the locale to use for retrieving the appropriate locale-specific string.fallback- iftrue, the global locale used by Openfire will be used if the requested locale is not available- Returns:
- the localized string.
-
getPluginResourceBundle
Retrieve theResourceBundlethat is used with this plugin.- Parameters:
pluginName- the name of the plugin.- Returns:
- the ResourceBundle used with this plugin.
- Throws:
Exception- thrown if an exception occurs.
-
getLocalizedString
public static String getLocalizedString(String key, Locale locale, List arguments, ResourceBundle bundle) Returns an internationalized string loaded from a resource bundle using the passed in Locale substituting the passed in arguments. Substitution is handled using theMessageFormatclass.- Parameters:
key- the key to use for retrieving the string from the appropriate resource bundle.locale- the locale to use for retrieving the appropriate locale-specific string.arguments- a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.bundle- The resource bundle from which to return the localized string.- Returns:
- the localized string.
-
getLocalizedNumber
Returns an internationalized String representation of the number using the default locale.- Parameters:
number- the number to format.- Returns:
- an internationalized String representation of the number.
-
getLocalizedNumber
Returns an internationalized String representation of the number using the specified locale.- Parameters:
number- the number to format.locale- the locale to use for formatting.- Returns:
- an internationalized String representation of the number.
-
getLocalizedNumber
Returns an internationalized String representation of the number using the default locale.- Parameters:
number- the number to format.- Returns:
- an internationalized String representation of the number.
-
getLocalizedNumber
Returns an internationalized String representation of the number using the specified locale.- Parameters:
number- the number to format.locale- the locale to use for formatting.- Returns:
- an internationalized String representation of the number.
-