Class I18nUtils

All Implemented Interfaces:
Initializable, Component, Contextualizable, LogEnabled, Serviceable
Direct Known Subclasses:
I18nUtils

Utils for i18n
  • Field Details

  • Constructor Details

  • Method Details

    • contextualize

      public void contextualize(Context context) throws ContextException
      Specified by:
      contextualize in interface Contextualizable
      Throws:
      ContextException
    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • initialize

      public void initialize() throws Exception
      Specified by:
      initialize in interface Initializable
      Throws:
      Exception
    • _createCache

      protected void _createCache()
      Create the i18n cache
    • _configure

      protected void _configure()
      Configure the i18n catalogue
    • getApplicationCatalogLocation

      Get the catalog location for application. context://WEB-INF/i18n
      Returns:
      the location
    • getParamCatalogLocation

      Get the catalog location form param. context://WEB-INF/param/[name]/i18n
      Parameters:
      name - the param name
      Returns:
      the location
    • getDefaultCatalogLocation

      Get the default catalog location for most typed cases (plugin, workspace at least). [type]:[name]://i18n
      Parameters:
      type - the type
      name - the name of the element (can be a plugin, workspace, etc.)
      Returns:
      the location
    • getOverridableCatalogLocation

      Get the overridable catalog location for most typed cases (plugin, workspace at least). context://WEB-INF/i18n/[type]s/[name]
      Parameters:
      type - the type
      name - the name of the element (can be a plugin, workspace, etc.)
      Returns:
      the location
    • 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

      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.
    • translate

      public String translate(I18nizable text)
      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

      public String translate(I18nizable text, String language) throws IllegalStateException
      Get the translation of the key.
      Parameters:
      text - The i18n key to translate
      language - 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 - The I18nizable to translate
      language - 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 translate
      language - 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

      protected Cache<org.ametys.core.util.I18nUtils.I18nKey,String> _getI18NCache()
      get the i18n cache (link language and I18nizable text to a translated value)
      Returns:
      the i18n cache