org.vostok.vaadin.addon.i18n
Class I18n

java.lang.Object
  extended by org.vostok.vaadin.addon.i18n.I18n

public class I18n
extends java.lang.Object

i18n is a centralized class to access translation, used internally by dialog, i18nbutton,etc...
You can add your own bundles, whom can provide new locales, override existing ones or just add application specific resources.

Every time you look for a key, I18n process from the most recent bundle to default one. Look up end when a key/value for the requested locale is found. If not, it returns I18n.UNKNOW (def, empty).
Default language set to user locale ( UI.getCurrent().getLocale() )
German translation by Julie Rabier. 1.1.2 : corrected default resource bundle See sample at http://vaadin.vostoksystem.eu

Version:
1.1.2
Author:
levreau.jerome@vostoksystem.eu

Constructor Summary
I18n()
           
 
Method Summary
static void addBundlePath(java.lang.String path)
          Extend or override resource bundle.
static java.lang.String[] getBundlePath()
          return local bundle
static java.lang.String getString(java.lang.String key)
          Translation for key key in user locale.
static java.lang.String getString(java.lang.String key, java.util.Locale locale)
          Translation for key key with locale locale.
static java.lang.String parse(java.lang.String key, java.util.Locale locale, java.lang.String... token)
          same as getString but replace any token in the source string with token Token's source format is {0}, {1}, etc... {} is an alias for {0].
static java.lang.String parse(java.lang.String key, java.util.Locale locale, java.lang.String replace, java.lang.String... token)
          same as getString but replace any token in the source string with token Token's source format is {0}, {1}, etc... {} is an alias for {0].
static java.lang.String parse(java.lang.String key, java.lang.String... token)
          same as getString but replace any token in the source string with token Token's source format is {0}, {1}, etc... {} is an alias for {0].
static void removeBundlePath(java.lang.String path)
          remove bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

I18n

public I18n()
Method Detail

addBundlePath

public static void addBundlePath(java.lang.String path)
                          throws java.util.MissingResourceException
Extend or override resource bundle.
When looking for a key, check is done from newer to older bundle.
Keep in mind a key in a newer bundle for default languare (en) will hide an older one, whatever locale is.

Parameters:
path - path to new resource file, set null, to clear user bundle
Throws:
java.util.MissingResourceException - if bundle doesn't exist

getBundlePath

public static java.lang.String[] getBundlePath()
return local bundle

Returns:
String[] list of bundle, can be empty but newer null.

removeBundlePath

public static void removeBundlePath(java.lang.String path)
remove bundle.

Parameters:
path - bundle to remove. if doens't exit, does nothing
Since:
1.1

getString

public static java.lang.String getString(java.lang.String key)
Translation for key key in user locale.
When looking for a key, check is done from newer to older bundle.
Keep in mind a key in a newer bundle for default languare (en) will hide an older one, whatever locale is.

Parameters:
key - i18n key
Returns:
String for key. In user locale, or english, or "unknow" if key not found

getString

public static java.lang.String getString(java.lang.String key,
                                         java.util.Locale locale)
Translation for key key with locale locale.
When looking for a key, check is done from newer to older bundle.
Keep in mind a key in a newer bundle for default languare (en) will hide an older one, whatever locale is.

Parameters:
key - i18n key.
locale - locale to use
Returns:
String for key. In user locale, or english, or UNKNOW if key not found or null

parse

public static java.lang.String parse(java.lang.String key,
                                     java.lang.String... token)
same as getString but replace any token in the source string with token Token's source format is {0}, {1}, etc... {} is an alias for {0]. If a token doesn't exist, it's ignored.
Note you cannot use { or } chars and token together. you have to use getString and parse the string by yourself.

token[0] is {0}, token[1] is {1} and so on.

don't use this method if your string has no token ! use getString instead

Parameters:
key - i18n key.
token - String[] of token(s). optional
Returns:
tokenised String or UNKNOW if key not found or null

parse

public static java.lang.String parse(java.lang.String key,
                                     java.util.Locale locale,
                                     java.lang.String... token)
same as getString but replace any token in the source string with token Token's source format is {0}, {1}, etc... {} is an alias for {0]. If a token doesn't exist, it's ignored.
Note you cannot use { or } chars and token together. you have to use getString and parse the string by yourself
token[0] is {0}, token[1] is {1} and so on.

don't use this method if your string has no token ! use getString instead

Parameters:
key - i18n key.
locale - locale to use
token - String[] of token(s). optional
Returns:
tokenised String or UNKNOW if key not found or null

parse

public static java.lang.String parse(java.lang.String key,
                                     java.util.Locale locale,
                                     java.lang.String replace,
                                     java.lang.String... token)
same as getString but replace any token in the source string with token Token's source format is {0}, {1}, etc... {} is an alias for {0]. If a token doesn't exist, it's ignored.
Note you cannot use { or } chars and token together. you have to use getString and parse the string by yourself
token[0] is {0}, token[1] is {1} and so on.

don't use this method if your string has no token ! use getString instead

Parameters:
key -
locale - locale to use
replace - String to subtstitute unkonw token. default to empty string
token - String[] of token(s). optional
Returns:
tokenised String or UNKNOW if key not found or null