public class I18n extends Object
nuiton-utils.
This class is a facility for internationalization. To use it in your soft,
you can either : | Modifier and Type | Field and Description |
|---|---|
protected static I18nFilter |
filter
Filtre a appliquer avant de retourner les chaines
|
protected static I18nInitializer |
initializer
Deprecated.
since 2.1, will be removed in version 3.0, in stead use the
method
init(I18nInitializer, Locale) which
will pass directly the initializer to the store. |
protected static I18nMessageFormatter |
messageFormatter
Formatter to apply on each translation.
|
protected static I18nStore |
store
I18n store of languages
|
| Constructor and Description |
|---|
I18n() |
| Modifier and Type | Method and Description |
|---|---|
static String |
_(String message,
Object... args)
Deprecated.
since 2.9, will be removed soon or later (hopes before Java SE 9), as part of syntax
keyword for lambda functions. Prefer use now method
t(String, Object...) |
protected static String |
applyFilter(String message)
Applique le filtre s'il y en a un
|
protected static void |
checkInit()
Checks if the I18n was initialized and if not as a fall-back, init it
with default initializer and default locale.
|
static void |
close()
Close i18n caches, says the store if exists.
|
protected static I18nLanguage |
getCurrentLanguage()
Obtain the registred language from the store.
|
protected static I18nInitializer |
getDefaultInitializer() |
static Locale |
getDefaultLocale()
Obtain the default locale setted in I18n.
|
protected static I18nFilter |
getFilter() |
protected static I18nLanguage |
getLanguage(Locale locale)
Obtain the language for the given
locale. |
static I18nMessageFormatter |
getMessageFormatter() |
static I18nStore |
getStore()
Get the i18n store.
|
static boolean |
hasKey(Locale locale,
String message)
|
static boolean |
hasKey(String message)
Look into the default
I18nLanguage if the given message
can be found. |
static void |
init(I18nInitializer initializer,
Locale locale)
Initialize I18n system.
|
protected static void |
initStore(I18nInitializer initializer,
Locale locale)
Init the store with given parameters and set the current language in the
store to the default given
locale. |
static String |
l_(Locale locale,
String message,
Object... args)
Deprecated.
since 2.9, will be removed soon or later, prefer use now method
l(Locale, String, Object...) |
static String |
l(Locale locale,
String message,
Object... args)
Retourne la chaine traduite si possible dans la locale demandée.
|
static String |
n_(String message,
Object... args)
Deprecated.
since 2.9, will be removed soon or later, prefer use now method
n(String, Object...) |
static String |
n(String message,
Object... args)
Retourne la chaine passée en argument.
|
static void |
reload() |
static void |
setDefaultLocale(Locale locale)
Sets the default locale used by I18n for the method
t(String, Object...). |
static void |
setFilter(I18nFilter filter)
Change le filtre des chaines traduites
|
static String |
t(String message,
Object... args)
Retourne la chaine traduite si possible.
|
@Deprecated protected static I18nInitializer initializer
init(I18nInitializer, Locale) which
will pass directly the initializer to the store.protected static I18nStore store
protected static I18nFilter filter
protected static I18nMessageFormatter messageFormatter
initializer used to configure the I18n system.I18nInitializer.setMessageFormatter(I18nMessageFormatter)public static void setFilter(I18nFilter filter)
filter - l'objet filtre a utiliserpublic static void init(I18nInitializer initializer, Locale locale)
initializer can be null, in that case it will use the default
implementation of it given by the method getDefaultInitializer().
The locale can also be null, and in that case we will use the
default locale of the system given by the method
Locale.getDefault().
We strongly recommand not to use the default initializer,
since this one scanq all the class-path to detects i18n files and can
NOT garantee the order of loading such files.
Prefer use at least the DefaultI18nInitializer instead.
In version 3.0, we will try to make the DefaultI18nInitializer the
default initializer using a convention over i18n files names.initializer - the initializer to use to detect bundleslocale - the default locale to usepublic static void reload()
public static void setDefaultLocale(Locale locale)
t(String, Object...). *
As a side effect, it will also set this locale is the default locale in
the system (says the method Locale.getDefault() will return the
given locale).
Note : The I18n system must have been initialized by one of the
init method.locale - the new default locale.public static Locale getDefaultLocale()
t(String, Object...).
Note : The I18n system must have been initialized by one of the
init method.public static boolean hasKey(String message)
I18nLanguage if the given message
can be found.message - the message to check presencegetDefaultLocale(),
hasKey(java.util.Locale, String)public static boolean hasKey(Locale locale, String message)
locale - the locale to be used to get the I18nLanguagemessage - the message to check presence@Deprecated public static String l_(Locale locale, String message, Object... args)
l(Locale, String, Object...)locale - la locale dans lequel on souhaite la traductionmessage - message formate avec I18nMessageFormatterargs - les parametres pour le message.public static String l(Locale locale, String message, Object... args)
locale - la locale dans lequel on souhaite la traductionmessage - message formate avec I18nMessageFormatterargs - les parametres pour le message.@Deprecated public static String _(String message, Object... args)
t(String, Object...)message - message formate avec I18nMessageFormatterargs - les parametres pour le message.public static String t(String message, Object... args)
message - message formate avec I18nMessageFormatterargs - les parametres pour le message.@Deprecated public static String n_(String message, Object... args)
n(String, Object...)String key = "nuitonutils.key"; String result = l(key)fonctionnera, mais la chaine n'aura pas été marquée comme devant être internationalisé. Tres utile par exemple, pour crée des objets non internationnalisé, et devant être traduit seulement à leur lecture suivant la locale du lecteur et non du créateur.
message - message formate avec I18nMessageFormatterargs - les parametres pour le message.public static String n(String message, Object... args)
String key = "nuitonutils.key"; String result = l(key)fonctionnera, mais la chaine n'aura pas été marquée comme devant être internationalisé. Tres utile par exemple, pour crée des objets non internationnalisé, et devant être traduit seulement à leur lecture suivant la locale du lecteur et non du créateur.
message - message formate avec I18nMessageFormatterargs - les parametres pour le message.public static void close()
public static I18nStore getStore()
protected static String applyFilter(String message)
message - le message qui devrait etre retourne avant application du
filtre.protected static I18nLanguage getCurrentLanguage()
protected static I18nLanguage getLanguage(Locale locale)
locale.
If locale is null, it means we wants to use the language
registred in the store.
As a fallback if this language is not defined, we use the language of
the default locale of the store.locale - the required locale or null if we wants to use the
one from the storeprotected static I18nFilter getFilter()
public static I18nMessageFormatter getMessageFormatter()
protected static void initStore(I18nInitializer initializer, Locale locale) throws NullPointerException
locale.
All values must be none null.initializer - the initializer to use to detect bundleslocale - the default locale to set in the storeNullPointerException - if any parameter is nullprotected static I18nInitializer getDefaultInitializer()
protected static void checkInit()
init(I18nInitializer, Locale) is
mandatory if you want to be safe.Copyright © 2004–2014 CodeLutin. All rights reserved.