Package org.ametys.core.util
Class I18nUtils
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.core.util.I18nUtils
- All Implemented Interfaces:
Initializable,Component,Contextualizable,LogEnabled,Serviceable
- Direct Known Subclasses:
I18nUtils
public class I18nUtils
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable, Initializable
Utils for i18n
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classClass representing an i18n location -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ContextThe avalon contextprotected Map<String,I18nUtils.Location> I18n cataloguesprotected SourceResolverSource Resolverstatic final Stringi18n cache idstatic final StringThe avalon role -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidConfigure the i18n catalogueprotected voidCreate the i18n cacheget 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.voidClear the i18n cache.voidcontextualize(Context context) Get the name of folders into WEB-INF/param which contains i18n cataloguesvoidvoidReload the i18n catalogues and clear cache.voidservice(ServiceManager manager) translate(I18nizable text) Get the translation of the key.translate(I18nizable text, String language) Get the translation of the key.translate(I18nizable i18nizable, 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 Details
-
ROLE
The avalon role -
I18N_CACHE
i18n cache id -
_locations
I18n catalogues -
_context
The avalon context -
_resolver
Source Resolver
-
-
Constructor Details
-
I18nUtils
public I18nUtils()
-
-
Method Details
-
contextualize
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
service
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
initialize
- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
_createCache
Create the i18n cache -
_configure
Configure the i18n catalogue -
getParamsFoldersWithI18n
Get the name of folders into WEB-INF/param which contains i18n catalogues- Returns:
- the name of folders into WEB-INF/param which contains i18n catalogues
-
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. -
translate
Get the translation of the key.- 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
Get the translation of the key.- 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(I18nizable i18nizable, String language, boolean rawValue) throws IllegalStateException Get the translation of the key.- Parameters:
i18nizable- TheI18nizableto 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
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
-
_getI18NCache
get the i18n cache (link language and I18nizable text to a translated value)- Returns:
- the i18n cache
-