Class I18nService


  • public final class I18nService
    extends java.lang.Object
    This class provides services for internationalization (i18n)
    Since:
    v1.4.1
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<java.util.Locale> getAdminAvailableLocales()
      Returns supported locales for Lutece backoffice
      static ReferenceList getAdminLocales​(java.util.Locale locale)
      Returns a ReferenceList of available locales
      static java.lang.String getDateFormatShortPattern​(java.util.Locale locale)
      Get the short date format specified by a locale
      static java.util.Locale getDefaultLocale()
      Get the default Locale specified in properties file
      static java.lang.String getLocalizedDate​(java.util.Date date, java.util.Locale locale, int nDateFormat)
      Format a date according to the given locale
      static java.lang.String getLocalizedDateTime​(java.util.Date date, java.util.Locale locale, int nDateFormat, int nTimeFormat)
      Format a date according to the given locale
      static java.lang.String getLocalizedString​(java.lang.String strKey, java.lang.Object[] arguments, java.util.Locale locale)
      Returns the string corresponding to a given key for a given locale that use a MessageFormat pattern with arguments.
      static java.lang.String getLocalizedString​(java.lang.String strKey, java.util.Locale theLocale)
      Returns the string corresponding to a given key for a given locale
      Core key structure :
      portal.[admin, features, insert, rbac, search, site, style, system, users, util].key Plugin key structure :
      [plugin].key Module key structure :
      module.[plugin].[module].key
      static java.util.Enumeration<java.lang.String> getPluginBundleKeys​(java.lang.String strPluginName)
      returns the resource bundle keys of a plugin
      static java.lang.String localize​(java.lang.String strSource, java.util.Locale locale)
      This method localize a string.
      static <E extends Localizable>
      java.util.Collection<E>
      localizeCollection​(java.util.Collection<E> collection, java.util.Locale locale)
      Localize in place all items of a collection
      static <E extends Localizable>
      java.util.List<E>
      localizeCollection​(java.util.List<E> list, java.util.Locale locale)
      Localize in place all items of a list
      static void resetCache()
      Reset the caches
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • localize

        public static java.lang.String localize​(java.lang.String strSource,
                                                java.util.Locale locale)
        This method localize a string. It scans for localization keys and replace them by localized values.
        The localization key structure is : #{bundle.key}.
        bundle's values should be 'portal' or a plugin name.
        Parameters:
        strSource - The string that contains localization keys
        locale - The locale
        Returns:
        The localized string
      • getLocalizedString

        public static java.lang.String getLocalizedString​(java.lang.String strKey,
                                                          java.util.Locale theLocale)
        Returns the string corresponding to a given key for a given locale
        • Core key structure :
          portal.[admin, features, insert, rbac, search, site, style, system, users, util].key
        • Plugin key structure :
          [plugin].key
        • Module key structure :
          module.[plugin].[module].key
        Parameters:
        strKey - The key of the string
        theLocale - The locale
        Returns:
        The string corresponding to the key
      • getLocalizedString

        public static java.lang.String getLocalizedString​(java.lang.String strKey,
                                                          java.lang.Object[] arguments,
                                                          java.util.Locale locale)
        Returns the string corresponding to a given key for a given locale that use a MessageFormat pattern with arguments.
        Parameters:
        arguments - The arguments used as values by the formatter
        strKey - The key of the string that contains the pattern
        locale - The locale
        Returns:
        The string corresponding to the key
      • getLocalizedDate

        public static java.lang.String getLocalizedDate​(java.util.Date date,
                                                        java.util.Locale locale,
                                                        int nDateFormat)
        Format a date according to the given locale
        Parameters:
        date - The date to format
        locale - The locale
        nDateFormat - A DateFormat constant corresponding to the expected format. (ie: DateFormat.FULL)
        Returns:
        The formatted date
      • getLocalizedDateTime

        public static java.lang.String getLocalizedDateTime​(java.util.Date date,
                                                            java.util.Locale locale,
                                                            int nDateFormat,
                                                            int nTimeFormat)
        Format a date according to the given locale
        Parameters:
        date - The date to format
        locale - The locale
        nDateFormat - A DateFormat constant corresponding to the expected format. (ie: DateFormat.FULL)
        nTimeFormat - A TimeFormat constant corresponding to the expected format. (ie: DateFormat.SHORT)
        Returns:
        The formatted date
      • getAdminAvailableLocales

        public static java.util.List<java.util.Locale> getAdminAvailableLocales()
        Returns supported locales for Lutece backoffice
        Returns:
        A list of locales
      • getDefaultLocale

        public static java.util.Locale getDefaultLocale()
        Get the default Locale specified in properties file
        Returns:
        The default Locale
      • getDateFormatShortPattern

        public static java.lang.String getDateFormatShortPattern​(java.util.Locale locale)
        Get the short date format specified by a locale
        Parameters:
        locale - The locale
        Returns:
        The localized short date pattern or null else
      • getAdminLocales

        public static ReferenceList getAdminLocales​(java.util.Locale locale)
        Returns a ReferenceList of available locales
        Parameters:
        locale - The locale to display available languages
        Returns:
        A ReferenceList of available locales
      • localizeCollection

        public static <E extends Localizable> java.util.Collection<E> localizeCollection​(java.util.Collection<E> collection,
                                                                                         java.util.Locale locale)
        Localize in place all items of a collection
        Type Parameters:
        E - the type of the elements of the collection
        Parameters:
        collection - The collection to localize
        locale - The locale
        Returns:
        The localized collection passed as argument
      • localizeCollection

        public static <E extends Localizable> java.util.List<E> localizeCollection​(java.util.List<E> list,
                                                                                   java.util.Locale locale)
        Localize in place all items of a list
        Type Parameters:
        E - the type of the elements of the list
        Parameters:
        list - The list to localize
        locale - The locale
        Returns:
        The localized collection passed as argument
      • resetCache

        public static void resetCache()
        Reset the caches
        Since:
        5.1
      • getPluginBundleKeys

        public static java.util.Enumeration<java.lang.String> getPluginBundleKeys​(java.lang.String strPluginName)
        returns the resource bundle keys of a plugin
        Parameters:
        strPluginName -
        Returns:
        the enumeration