org.nuiton.i18n
Class I18n

java.lang.Object
  extended by org.nuiton.i18n.I18n

public class I18n
extends Object

New generation I18n class.

Note: This class replace the previous one in project nuiton-utils.

This class is a facility for internationalization. To use it in your soft, you can either :

Since:
1.1
Author:
tchemit

Field Summary
static String DEFAULT_ENCODING
           
static Locale DEFAULT_LOCALE
           
protected static I18nFilter filter
          Filtre a appliquer avant de retourner les chaines
protected static I18nInitializer initializer
          I18n initializer
static String ISO_8859_1_ENCONDING
           
protected static I18nStore store
          I18n store of languages
static String UTF_8_ENCONDING
           
 
Constructor Summary
I18n()
           
 
Method Summary
static String _(String message)
          Retourne la chaine traduite si possible.
static String _(String message, Object... args)
          Retourne la chaine traduite si possible.
protected static String applyFilter(String message)
          Applique le filtre s'il y en a un
static void close()
          close i18n caches, says the store if exists

This method should be called to reset all caches (languages, bundles,...)

protected static I18nLanguage getCurrentLanguage()
           
protected static I18nFilter getFilter()
           
static I18nInitializer getInitializer()
           
static I18nStore getLoader()
          Deprecated. since 1.1, only keep for compatibility
static I18nStore getStore()
          Get the i18n store.
static void init()
          Initialise la librairie avec encoding par defaut et locale par defaut
static void init(Locale locale)
          Initialize the library for given locale with DEFAULT_ENCODING.
static void init(String language, String country)
          Initialise la librairie
static String n_(String message)
          Retourne la chaine passé en argument.
static String n_(String message, Object... args)
          Retourne la chaine passée en argument.
static Locale newLocale(String str)
          Deprecated. since 1.1, prefer use the I18nUtil.newLocale(String)
static Locale newLocale(String language, String country)
          Deprecated. since 1.1, prefer use the I18nUtil.newLocale(String,String)
static Locale[] parseLocales(String str)
          Deprecated. since 1.1, prefer use the I18nUtil.parseLocales(String)
static void setFilter(I18nFilter filter)
          Change le filtre des chaines traduites
static void setInitializer(I18nInitializer initializer)
          Sets the initializer to use to init the I18n system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ISO_8859_1_ENCONDING

public static final String ISO_8859_1_ENCONDING
See Also:
Constant Field Values

UTF_8_ENCONDING

public static final String UTF_8_ENCONDING
See Also:
Constant Field Values

DEFAULT_ENCODING

public static final String DEFAULT_ENCODING
See Also:
Constant Field Values

DEFAULT_LOCALE

public static final Locale DEFAULT_LOCALE

initializer

protected static I18nInitializer initializer
I18n initializer


store

protected static I18nStore store
I18n store of languages


filter

protected static I18nFilter filter
Filtre a appliquer avant de retourner les chaines

Constructor Detail

I18n

public I18n()
Method Detail

setInitializer

public static void setInitializer(I18nInitializer initializer)
Sets the initializer to use to init the I18n system.

You must inovke this method before any invocation of methods init(XXX).

Parameters:
initializer - the initializer to set.
See Also:
DefaultI18nInitializer

setFilter

public static void setFilter(I18nFilter filter)
Change le filtre des chaines traduites

Parameters:
filter - l'objet filtre a utiliser

init

public static void init()
Initialise la librairie avec encoding par defaut et locale par defaut


init

public static void init(String language,
                        String country)
Initialise la librairie

Parameters:
language - une chaine representant la langue à utiliser fr, en, ...
country - une chaine representant le pays à utiliser FR, GB, ...

init

public static void init(Locale locale)
Initialize the library for given locale with DEFAULT_ENCODING.

Parameters:
locale - language to use

_

public static String _(String message)
Retourne la chaine traduite si possible.

Parameters:
message - la chaine a traduire
Returns:
la traduction si possible ou la chaine passee en parametre sinon.

_

public static String _(String message,
                       Object... args)
Retourne la chaine traduite si possible.

Parameters:
message - message formate avec la meme syntaxe que String.format(java.lang.String, java.lang.Object...)
args - les parametres pour le message.
Returns:
la traduction si possible ou la chaine passee en parametre sinon.

n_

public static String n_(String message,
                        Object... args)
Retourne la chaine passée en argument.

Utile surtout pour collecter les chaines et ne pas les traduires à leur apparition.

Par exemple :

String key = "nuitonutils.key";
 String result = _(key)
fonctionnera, mais la chaine n'aura pas été marquée comme devant être internationalisé.

Tres utile par exemple, pour crée des objets non internationnalisé, et devant être traduit seulement à leur lecture suivant la locale du lecteur et non du créateur.

Parameters:
message - message formate avec la meme syntaxe que String.format(String, Object...)
args - les parametres pour le message.
Returns:
le message passe en argument mais formatté avec les parametres

n_

public static String n_(String message)
Retourne la chaine passé en argument.

Utile surtout pour collecter les chaines et ne pas les traduires à leur apparition.

Par exemple :

String key = "nuitonutils.key";
 String result = _(key)
fonctionnera, mais la chaine n'aura pas été marquée comme devant être internationalisé.

Tres utile par exemple, pour crée des objets non internationnalisé, et devant être traduit seulement à leur lecture suivant la locale du lecteur et non du créateur.

Parameters:
message - la chaine à traduire
Returns:
la chaine passée en argument.

close

public static void close()
close i18n caches, says the store if exists

This method should be called to reset all caches (languages, bundles,...)


getInitializer

public static I18nInitializer getInitializer()

getStore

public static I18nStore getStore()
Get the i18n store.

If store is not init, then instanciate it.

Returns:
the instanciated i18n store

applyFilter

protected static String applyFilter(String message)
Applique le filtre s'il y en a un

Parameters:
message - le message qui devrait etre retourne avant application du filtre.
Returns:
le message filtre

getCurrentLanguage

protected static I18nLanguage getCurrentLanguage()
Returns:
the current language of the store, or null if store is not init.

getFilter

protected static I18nFilter getFilter()

getLoader

@Deprecated
public static I18nStore getLoader()
Deprecated. since 1.1, only keep for compatibility

Returns:
the current store

parseLocales

@Deprecated
public static Locale[] parseLocales(String str)
                             throws IllegalArgumentException
Deprecated. since 1.1, prefer use the I18nUtil.parseLocales(String)

Parse a list of Locale seperated by comma.

Example : fr_FR,en_GB

Parameters:
str - the string representation of locale separated by comma
Returns:
list of available locales
Throws:
IllegalArgumentException - ia a locale is not valid

newLocale

@Deprecated
public static Locale newLocale(String str)
Deprecated. since 1.1, prefer use the I18nUtil.newLocale(String)

Parameters:
str - the text representation of the locale
Returns:
the locale, or default locale if could not parse the given one

newLocale

@Deprecated
public static Locale newLocale(String language,
                                          String country)
Deprecated. since 1.1, prefer use the I18nUtil.newLocale(String,String)

Parameters:
language - the language of the locale
country - the country of the locale
Returns:
the required locale


Copyright © 2004-2010 CodeLutin. All Rights Reserved.