| java.lang.Object org.zkoss.util.Locales
Locales | public class Locales (Code) | | The locale relevant utilities.
author: tomyeh |
Method Summary | |
public static Locale | getByFallback(Collection values, Locale locale) Returns any occurence of the specified Locale or any its fallback
in the value collection, or null if not found. | final public static Locale | getCurrent() Returns the current locale; never null.
This is the locale that every other objects shall use,
unless they have special consideration.
Default: If
Locales.setThreadLocal was called with non-null,
the value is returned. | final public static Locale | getLocale(String localeString, char separator) Converts a string that consists of language, country and variant
to a locale. | final public static Locale | getLocale(String localeString) Converts a string that consists of language, country and variant
to a locale. | final public static synchronized Locale | getLocale(Locale locale) Converts a Locale to one of them being used before. | final public static Locale | getThreadLocal() Returns the locale defined by
Locales.setThreadLocal . | public static int | indexOfUnderline(String s, int j) Returns the index of '_' preceding the country part, starting from j. | public static int | indexOfUnderline(String s) Returns the index of '_' preceding the country part. | final public static Locale | setThreadLocal(Locale locale) Sets the locale for the current thread only. | final public static boolean | testCurrent(String lang, String country) Returns whether the current locale (
Locales.getCurrent ) belongs
to the specified language and/or country.
Parameters: lang - the language code, e.g., en and zh. |
getByFallback | public static Locale getByFallback(Collection values, Locale locale)(Code) | | Returns any occurence of the specified Locale or any its fallback
in the value collection, or null if not found.
By fallback, we mean will try without variant and country.
Example, if locale is zh_TW, it will try zh_TW and then zh.
|
getCurrent | final public static Locale getCurrent()(Code) | | Returns the current locale; never null.
This is the locale that every other objects shall use,
unless they have special consideration.
Default: If
Locales.setThreadLocal was called with non-null,
the value is returned. Otherwise, Locale.getDefault() is returned,
|
getLocale | final public static Locale getLocale(String localeString, char separator)(Code) | | Converts a string that consists of language, country and variant
to a locale.
The separator between language, country and variant
is customizable, and whitespaces are ignored, e.g.,
"zh_TW" and "zh, TW".
Thus, locale.equals(Locales.getLocale(locale.toString(), '_')).
Parameters: localeString - the locale in string; null is OK Parameters: separator - the separator; ((char)0) means to decide automatically(either ',' or '_') the locale or null if locale is null or empty |
getLocale | final public static Locale getLocale(String localeString)(Code) | | Converts a string that consists of language, country and variant
to a locale.
A shortcut: getLocale(localeString, (char)0).
|
getLocale | final public static synchronized Locale getLocale(Locale locale)(Code) | | Converts a Locale to one of them being used before.
To save memory (since locale is used frequently), it is suggested
to pass thru this method after creating a new instance of Locale.
Example, getLocale(new Locale(...)).
This method first look for any locale
|
indexOfUnderline | public static int indexOfUnderline(String s, int j)(Code) | | Returns the index of '_' preceding the country part, starting from j.
It is similar to s.indexOf('_', j), except it detects country part
(which must be only two letter in lower cases.
|
indexOfUnderline | public static int indexOfUnderline(String s)(Code) | | Returns the index of '_' preceding the country part.
It is similar to s.indexOf('_'), except it detects country part
(which must be only two letter in lower cases.
|
setThreadLocal | final public static Locale setThreadLocal(Locale locale)(Code) | | Sets the locale for the current thread only.
Each thread could have an independent locale, called
the thread locale.
When Invoking this method under a thread that serves requests,
remember to clean up the setting upon completing each request.
Locale old = Locales.setThreadLocal(newValue);
try {
...
} finally {
Locales.setThreadLocal(old);
}
Parameters: locale - the thread locale; null to denote no thread locale the previous thread locale |
testCurrent | final public static boolean testCurrent(String lang, String country)(Code) | | Returns whether the current locale (
Locales.getCurrent ) belongs
to the specified language and/or country.
Parameters: lang - the language code, e.g., en and zh. Ignored if null. Parameters: country - the country code, e.g., US. Ignored if null.If empty, it means no country code at all. |
|
|