public class I18nUtils extends AbstractLogEnabled implements Component, Serviceable, Contextualizable, Initializable, Disposable
Modifier and Type | Class and Description |
---|---|
private class |
I18nUtils.BufferHandler |
protected class |
I18nUtils.Location
Class representing an i18n location
|
Modifier and Type | Field and Description |
---|---|
private BundleFactory |
_bundleFactory |
private Map<String,Map<I18nizableText,String>> |
_cache |
protected Context |
_context
The avalon context
|
private static I18nUtils |
_instance |
protected Map<String,I18nUtils.Location> |
_locations
I18n catalogues
|
static String |
ROLE
The avalon role
|
Constructor and Description |
---|
I18nUtils() |
Modifier and Type | Method and Description |
---|---|
protected void |
_configure()
Configure the i18n catalogue
|
protected String |
_translate(I18nizableText text,
String language,
boolean rawValue)
Get the translation of the key.
|
void |
clearCache()
Clear the i18n cache.
|
void |
contextualize(Context context) |
void |
dispose() |
static I18nUtils |
getInstance()
Get the unique instance
|
protected Map<I18nizableText,String> |
getLangCache(String language)
Get the translation cache for a language.
|
void |
initialize() |
void |
reloadCatalogues()
Reload the i18n catalogues and clear cache.
|
void |
service(ServiceManager manager) |
String |
translate(I18nizableText text)
Get the translation of the key.
|
String |
translate(I18nizableText text,
String language)
Get the translation of the key.
|
String |
translate(I18nizableText text,
String language,
boolean rawValue)
Get the translation of the key.
|
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
protected Map<String,I18nUtils.Location> _locations
private BundleFactory _bundleFactory
public I18nUtils()
public void contextualize(Context context) throws ContextException
contextualize
in interface Contextualizable
ContextException
public void service(ServiceManager manager) throws ServiceException
service
in interface Serviceable
ServiceException
public void initialize() throws Exception
initialize
in interface Initializable
Exception
protected void _configure()
public void reloadCatalogues()
public static I18nUtils getInstance()
public String translate(I18nizableText text)
text
- The i18n key to translateIllegalStateException
- if an error occuredpublic String translate(I18nizableText text, String language) throws IllegalStateException
text
- The i18n key to translatelanguage
- The language code to use for translation. Can be null.IllegalStateException
- if an error occurredpublic String translate(I18nizableText text, String language, boolean rawValue) throws IllegalStateException
text
- The i18n key to translatelanguage
- The language code to use for translation. Can be null.rawValue
- Set true to get the value corresponding strictly to the specified Locale, without escalading to parent Locale if not found. Note that there is no cache for strict values.IllegalStateException
- if an error occurredpublic void clearCache()
protected Map<I18nizableText,String> getLangCache(String language)
language
- the language.protected String _translate(I18nizableText text, String language, boolean rawValue) throws IllegalStateException
text
- The i18n key to translatelanguage
- The language code to use for translation. Can be null.rawValue
- Set true to get the value corresponding strictly to the specified Locale, without escalading to parent Locale if not foundIllegalStateException
- if an error occuredpublic void dispose()
dispose
in interface Disposable