fr.paris.lutece.portal.service.i18n
Class I18nService

java.lang.Object
  extended by fr.paris.lutece.portal.service.i18n.I18nService

public final class I18nService
extends Object

This class provides services for internationalization (i18n)

Since:
v1.4.1

Method Summary
static List<Locale> getAdminAvailableLocales()
          Returns supported locales for Lutece backoffice
static ReferenceList getAdminLocales(Locale locale)
          Returns a ReferenceList of available locales
static String getDateFormatShortPattern(Locale locale)
          Get the short date format specified by a locale
static Locale getDefaultLocale()
          Get the default Locale specified in properties file
static String getLocalizedDate(Date date, Locale locale, int nDateFormat)
          Format a date according to the given locale
static String getLocalizedDateTime(Date date, Locale locale, int nDateFormat, int nTimeFormat)
          Format a date according to the given locale
static String getLocalizedString(String strKey, Locale theLocale)
          Returns the string corresponding to a given key for a given locale
Core key structure :
portal.
static String getLocalizedString(String strKey, Object[] arguments, Locale locale)
          Returns the string corresponding to a given key for a given locale that use a MessageFormat pattern with arguments.
static String localize(String strSource, Locale locale)
          This method localize a string.
static Collection localizeCollection(Collection<? extends Localizable> collection, Locale locale)
          Localize all items of a list
static List localizeCollection(List<? extends Localizable> list, Locale locale)
          Localize all items of a list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

localize

public static String localize(String strSource,
                              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 String getLocalizedString(String strKey,
                                        Locale theLocale)
Returns the string corresponding to a given key for a given locale

Parameters:
strKey - The key of the string
theLocale - The locale
Returns:
The string corresponding to the key

getLocalizedString

public static String getLocalizedString(String strKey,
                                        Object[] arguments,
                                        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 String getLocalizedDate(Date date,
                                      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 String getLocalizedDateTime(Date date,
                                          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 List<Locale> getAdminAvailableLocales()
Returns supported locales for Lutece backoffice

Returns:
A list of locales

getDefaultLocale

public static Locale getDefaultLocale()
Get the default Locale specified in properties file

Returns:
The default Locale

getDateFormatShortPattern

public static String getDateFormatShortPattern(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(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 Collection localizeCollection(Collection<? extends Localizable> collection,
                                            Locale locale)
Localize all items of a list

Parameters:
collection - The list to localize
locale - The locale
Returns:
The localized collection

localizeCollection

public static List localizeCollection(List<? extends Localizable> list,
                                      Locale locale)
Localize all items of a list

Parameters:
list - The list to localize
locale - The locale
Returns:
The localized collection


Copyright © 2014 Mairie de Paris. All Rights Reserved.