Package org.ametys.core.util
Class I18nUtils
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.core.util.I18nUtils
-
- All Implemented Interfaces:
Disposable,Initializable,Component,Contextualizable,LogEnabled,Serviceable
- Direct Known Subclasses:
I18nUtils
public class I18nUtils extends AbstractLogEnabled implements Component, Serviceable, Contextualizable, Initializable, Disposable
Utils for i18n
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classI18nUtils.BufferHandler(package private) static classI18nUtils.I18nKeyprotected static classI18nUtils.LocationClass representing an i18n location
-
Field Summary
Fields Modifier and Type Field Description private static String__I18N_CACHEprivate BundleFactory_bundleFactoryprivate AbstractCacheManager_cacheManagerprotected Context_contextThe avalon contextprivate static I18nUtils_instanceprotected Map<String,I18nUtils.Location>_locationsI18n cataloguesstatic StringROLEThe avalon role
-
Constructor Summary
Constructors Constructor Description I18nUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_configure()Configure the i18n catalogueprotected void_createCache()Create the i18n cacheprotected Cache<I18nUtils.I18nKey,String>_getI18NCache()get the i18n cache (link language and I18nizable text to a translated value)protected String_translate(I18nizableText text, String language, boolean rawValue)Get the translation of the key.voidclearCache()Clear the i18n cache.voidcontextualize(Context context)voiddispose()static I18nUtilsgetInstance()Get the unique instancevoidinitialize()voidreloadCatalogues()Reload the i18n catalogues and clear cache.voidservice(ServiceManager manager)Stringtranslate(I18nizableText text)Get the translation of the key.Stringtranslate(I18nizableText text, String language)Get the translation of the key.Stringtranslate(I18nizableText text, String language, boolean rawValue)Get the translation of the key.-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
__I18N_CACHE
private static final String __I18N_CACHE
-
_locations
protected Map<String,I18nUtils.Location> _locations
I18n catalogues
-
_bundleFactory
private BundleFactory _bundleFactory
-
_cacheManager
private AbstractCacheManager _cacheManager
-
-
Constructor Detail
-
I18nUtils
public I18nUtils()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
_createCache
protected void _createCache()
Create the i18n cache
-
_configure
protected void _configure()
Configure the i18n catalogue
-
reloadCatalogues
public void reloadCatalogues()
Reload the i18n catalogues and clear cache. This method should be called as soon as the list of i18n catalogue was changed, when adding a new catalogue for example.
-
getInstance
public static I18nUtils getInstance()
Get the unique instance- Returns:
- the unique instance
-
translate
public String translate(I18nizableText text)
Get the translation of the key. This method is slow. Only use in very specific cases (send mail for example)- Parameters:
text- The i18n key to translate- Returns:
- The translation or null if there's no available translation
- Throws:
IllegalStateException- if an error occured
-
translate
public String translate(I18nizableText text, String language) throws IllegalStateException
Get the translation of the key. Only use in very specific cases (send mail for example)- Parameters:
text- The i18n key to translatelanguage- The language code to use for translation. Can be null.- Returns:
- The translation or null if there's no available translation
- Throws:
IllegalStateException- if an error occurred
-
translate
public String translate(I18nizableText text, String language, boolean rawValue) throws IllegalStateException
Get the translation of the key. Only use in very specific cases (send mail for example)- Parameters:
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.- Returns:
- The translation or null if there's no available translation
- Throws:
IllegalStateException- if an error occurred
-
clearCache
public void clearCache()
Clear the i18n cache.
-
_translate
protected String _translate(I18nizableText text, String language, boolean rawValue) throws IllegalStateException
Get the translation of the key. Only use in very specific cases (send mail for example)- Parameters:
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- Returns:
- The translation or null if there's no available translation
- Throws:
IllegalStateException- if an error occured
-
dispose
public void dispose()
- Specified by:
disposein interfaceDisposable
-
_getI18NCache
protected Cache<I18nUtils.I18nKey,String> _getI18NCache()
get the i18n cache (link language and I18nizable text to a translated value)- Returns:
- the i18n cache
-
-