public class NLS
extends java.lang.Object
The setLocale(Locale)
method is used to configure locale for the
calling thread. The locale setting is thread inheritable. This means that a
child thread will have the same locale setting as its creator thread until it
changes it explicitly.
Example of usage:
NLS.setLocale(Locale.GERMAN); TransportText t = NLS.getBundleFor(TransportText.class);
Modifier and Type | Field and Description |
---|---|
private static java.lang.InheritableThreadLocal<NLS> |
local |
private java.util.Locale |
locale |
private java.util.concurrent.ConcurrentHashMap<java.lang.Class,TranslationBundle> |
map |
static java.util.Locale |
ROOT_LOCALE
The root locale constant.
|
Modifier | Constructor and Description |
---|---|
private |
NLS(java.util.Locale locale) |
Modifier and Type | Method and Description |
---|---|
private <T extends TranslationBundle> |
get(java.lang.Class<T> type) |
static <T extends TranslationBundle> |
getBundleFor(java.lang.Class<T> type)
Returns an instance of the translation bundle of the required type.
|
static void |
setLocale(java.util.Locale locale)
Sets the locale for the calling thread.
|
private static NLS |
useJVMDefaultInternal() |
static void |
useJVMDefaultLocale()
Sets the JVM default locale as the locale for the calling thread.
|
public static final java.util.Locale ROOT_LOCALE
private static final java.lang.InheritableThreadLocal<NLS> local
private final java.util.Locale locale
private final java.util.concurrent.ConcurrentHashMap<java.lang.Class,TranslationBundle> map
public static void setLocale(java.util.Locale locale)
The getBundleFor(Class)
method will honor this setting if it
is supported by the provided resource bundle property files. Otherwise,
it will use a fall back locale as described in the
TranslationBundle
locale
- the preferred localepublic static void useJVMDefaultLocale()
Semantically this is equivalent to
NLS.setLocale(Locale.getDefault())
.
private static NLS useJVMDefaultInternal()
public static <T extends TranslationBundle> T getBundleFor(java.lang.Class<T> type)
TranslationBundle
.type
- required bundle typeTranslationBundleLoadingException
- see
TranslationBundleLoadingException
TranslationStringMissingException
- see
TranslationStringMissingException
private <T extends TranslationBundle> T get(java.lang.Class<T> type)