Index: lutinutil/src/java/org/codelutin/i18n/I18n.java diff -u lutinutil/src/java/org/codelutin/i18n/I18n.java:1.4 lutinutil/src/java/org/codelutin/i18n/I18n.java:1.5 --- lutinutil/src/java/org/codelutin/i18n/I18n.java:1.4 Tue Jan 1 18:43:26 2008 +++ lutinutil/src/java/org/codelutin/i18n/I18n.java Tue Jan 1 19:20:26 2008 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Mise a jour: $Date: 2008-01-01 18:43:26 $ + * Mise a jour: $Date: 2008-01-01 19:20:26 $ * par : $Author: tchemit $ */ @@ -33,6 +33,7 @@ import java.text.MessageFormat; import java.util.Locale; +import java.util.Arrays; import java.util.logging.Logger; import java.io.InputStream; @@ -41,9 +42,9 @@ * you can either : * * * - *@author poussin - *@author tchemit - *@created 2 decembre 2003 + * @author poussin + * @author chemit + * @created 2 decembre 2003 */ public class I18n { + private static final LanguageEnum DEFAULT_LANGUAGE= LanguageEnum.en; + + private static final CountryEnum DEFAULT_COUNTRY= CountryEnum.US; + private static final String ISO_8859_1_ENCONDING = "ISO-8859-1"; - + private static final String UTF_8_ENCONDING = "UTF-8"; /** + * Initialize the library with default language {@link #DEFAULT_LANGUAGE} + * and default country {@link #DEFAULT_COUNTRY} with + * ISO-8859-1 enconding + */ + public static void initISO88591() { + setLanguage(DEFAULT_LANGUAGE, DEFAULT_COUNTRY, ISO_8859_1_ENCONDING); + } + + /** * Initialize the library for given language with * ISO-8859-1 enconding * @@ -83,6 +97,15 @@ } /** + * Initialize the library with default language {@link #DEFAULT_LANGUAGE} + * and default country {@link #DEFAULT_COUNTRY} with + * UTF-8 enconding + */ + public static void initUTF8() { + setLanguage(DEFAULT_LANGUAGE, DEFAULT_COUNTRY, UTF_8_ENCONDING); + } + + /** * Initialize the library for given language with * UTF-8 enconding * @@ -146,8 +169,7 @@ try { return applyFilter(MessageFormat.format(message, args)); } catch (Exception zzz) { - Logger.getLogger("org.codelutin.i18n.I18n").warning( - "Message can't be translated: '" + message + "'"); + Logger.getLogger("org.codelutin.i18n.I18n").warning(_("lutinutil.error.i18n.untranslated.message", message)); return applyFilter(message); } } @@ -177,13 +199,25 @@ try { return MessageFormat.format(message, args); } catch (Exception eee) { - Logger.getLogger("org.codelutin.i18n.I18n").warning( - "Message can't be formated: '" + message + "'"); + Logger.getLogger("org.codelutin.i18n.I18n").warning(_("lutinutil.error.i18n.unformated.message", message, Arrays.toString(args))); return message; } } /** + * Change le filtre des chaines traduites + * + * @param filter l'objet filtre a utiliser + */ + public static void setFilter(I18nFilter filter) { + I18n.filter = filter; + } + + public static void setRecordFilePath(String recordFilePath) { + I18n.recordFilePath = recordFilePath; + } + + /** * Applique le filtre s'il y en a un * * @param message le message qui devrait etre retourne avant application du @@ -205,7 +239,7 @@ * @see LanguageEnum */ protected static void init0(String language, String toEncoding) { - LanguageEnum languageVal = getLanguage(language); + LanguageEnum languageVal = LanguageEnum.valueOf(language,DEFAULT_LANGUAGE); setLanguage(languageVal, toEncoding); } @@ -219,12 +253,11 @@ * @see CountryEnum */ protected static void init0(String language, String country, String toEncoding) { - LanguageEnum languageValue = getLanguage(language); - CountryEnum countryValue = getCountry(country); + LanguageEnum languageValue = LanguageEnum.valueOf(language,DEFAULT_LANGUAGE); + CountryEnum countryValue = CountryEnum.valueOf(country,DEFAULT_COUNTRY); setLanguage(languageValue, countryValue, toEncoding); } - /** * Initialise la librairie. * @@ -235,7 +268,6 @@ I18n.language = new Language(new Locale(language)); } - /** * Initialise la librairie * @@ -247,19 +279,6 @@ I18n.language = new Language(new Locale(language, country)); } - /** - * Change le filtre des chaines traduites - * - * @param filter l'objet filtre a utiliser - */ - public static void setFilter(I18nFilter filter) { - I18n.filter = filter; - } - - public static void setRecordFilePath(String recordFilePath) { - I18n.recordFilePath = recordFilePath; - } - protected static void setLanguage(LanguageEnum language, String toEncoding) { I18n.language = new Language(new Locale(language.name()), toEncoding); } @@ -268,23 +287,4 @@ I18n.language = new Language(new Locale(language.name(),country.name()), toEncoding); } - public static LanguageEnum getLanguage(String language) { - try { - LanguageEnum languageValue; - languageValue = LanguageEnum.valueOf(language.toLowerCase()); - return languageValue; - }catch (NullPointerException e) { - throw new IllegalArgumentException(e); - } - } - - public static CountryEnum getCountry(String country) { - try { - CountryEnum countryValue; - countryValue = CountryEnum.valueOf(country.toUpperCase()); - return countryValue; - }catch (NullPointerException e) { - throw new IllegalArgumentException(e); - } - } } //I18n