Author: tchemit Date: 2011-01-21 11:13:01 +0100 (Fri, 21 Jan 2011) New Revision: 1852 Url: http://nuiton.org/repositories/revision/i18n/1852 Log: improve I18n loading design Modified: trunk/nuiton-i18n/pom.xml trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nStore.java trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nStoreTest.java trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java trunk/src/site/apt/index.apt Modified: trunk/nuiton-i18n/pom.xml =================================================================== --- trunk/nuiton-i18n/pom.xml 2011-01-20 15:17:58 UTC (rev 1851) +++ trunk/nuiton-i18n/pom.xml 2011-01-21 10:13:01 UTC (rev 1852) @@ -53,6 +53,11 @@ </dependency> <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + + <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java 2011-01-20 15:17:58 UTC (rev 1851) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java 2011-01-21 10:13:01 UTC (rev 1852) @@ -57,15 +57,30 @@ /** Logger */ private static final Log log = LogFactory.getLog(I18n.class); + /** @deprecated since 2.1, will be removed in version 3.0 */ + @Deprecated public static final String ISO_8859_1_ENCONDING = "ISO-8859-1"; + /** @deprecated since 2.1, will be removed in version 3.0 */ + @Deprecated public static final String UTF_8_ENCONDING = "UTF-8"; + /** @deprecated since 2.1, will be removed in version 3.0 */ + @Deprecated public static final String DEFAULT_ENCODING = ISO_8859_1_ENCONDING; + /** @deprecated since 2.1, will be removed in version 3.0 */ + @Deprecated public static final Locale DEFAULT_LOCALE = Locale.UK; - /** I18n initializer */ + /** + * I18n initializer, + * + * @deprecated since 2.1, will be removed in version 3.0, in stead use the + * method {@link I18n#init(I18nInitializer, Locale)} which + * will pass directly the initializer to the store. + */ + @Deprecated protected static I18nInitializer initializer; /** I18n store of languages */ @@ -74,7 +89,7 @@ /** Filtre a appliquer avant de retourner les chaines */ protected static I18nFilter filter; - public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; /** * Sets the initializer to use to init the I18n system. @@ -84,7 +99,10 @@ * * @param initializer the initializer to set. * @see DefaultI18nInitializer + * @deprecated since 2.1, will be removed in version 3.0, use instead the + * method {@link I18n#init(I18nInitializer, Locale)}. */ + @Deprecated public static void setInitializer(I18nInitializer initializer) { I18n.initializer = initializer; } @@ -98,63 +116,156 @@ I18n.filter = filter; } - /** Initialise la librairie avec encoding par defaut et locale par defaut */ + /** + * Initialize I18n with default initializer and default locale of the system. + * <p/> + * <strong>We recommand not to use any longer this method.</strong> + * + * @deprecated since 2.1, will be removed in version 3.0, prefer use the + * {@link #init(I18nInitializer, Locale)} instead. + */ + @Deprecated public static void init() { - init(null); + if (log.isWarnEnabled()) { + log.warn("Using deprecated init method."); + } + init(getDefaultInitializer(), null); } /** - * Initialise la librairie + * Initialize I18n with default initializer and given locale. + * <p/> + * <strong>We recommand not to use any longer this method.</strong> * * @param language une chaine representant la langue à utiliser fr, en, ... * @param country une chaine representant le pays à utiliser FR, GB, ... + * @deprecated since 2.1, will be removed in version 3.0, prefer use the + * {@link #init(I18nInitializer, Locale)} instead. */ + @Deprecated public static void init(String language, String country) { - init(I18nUtil.newLocale(language, country)); + if (log.isWarnEnabled()) { + log.warn("Using deprecated init method."); + } + init(getDefaultInitializer(), I18nUtil.newLocale(language, country)); } /** - * Initialize the library for given <code>locale</code> with {@link - * #DEFAULT_ENCODING}. + * Initialize I18n with default initializer and given {@code locale}. + * <p/> + * <strong>We recommand not to use any longer this method.</strong> * * @param locale language to use + * @deprecated since 2.1, will be removed in version 3.0, prefer use the + * {@link #init(I18nInitializer, Locale)} instead. */ + @Deprecated public static void init(Locale locale) { + if (log.isWarnEnabled()) { + log.warn("Using deprecated init method."); + } + init(getDefaultInitializer(), locale); + } + + /** + * Initialize I18n system. + * <p/> + * The {@code initializer} can be null, in that case it will use the default + * implementation of it given by the method {@link I18n#getDefaultInitializer()}. + * <p/> + * The {@code locale} can also be null, and in that case we will use the + * default locale of the system given by the method + * {@link Locale#getDefault()}. + * <p/> + * <strong>We strongly recommand not to use the default initializer</strong>, + * since this one scanq all the class-path to detects i18n files and can + * <strong>NOT</strong> garantee the order of loading such files. + * <p/> + * Prefer use at least the {@link DefaultI18nInitializer} instead. + * <p/> + * In version 3.0, we will try to make the {@link DefaultI18nInitializer} the + * default initializer using a convention over i18n files names. + * + * @param initializer the initializer to use to detect bundles + * @param locale the default locale to use + * @since 2.1 + */ + public static void init(I18nInitializer initializer, Locale locale) { + + if (initializer == null) { + + // get a default initializer + initializer = getDefaultInitializer(); + } + if (locale == null) { // use default locale locale = I18nUtil.newLocale(null, null); } - // let the store use this locale - getStore().setLanguage(locale); + initStore(initializer, locale); } + public static void reload() throws IllegalStateException { + + checkInit(); + + // get back initializer + I18nInitializer initializer = store.getResolver(); + + // get back default locale + Locale locale = store.getCurrentLocale(); + + // close the current store + close(); + + // reload store + init(initializer, locale); + } + /** - * Retourne la chaine traduite si possible dans la locale demandée. + * Sets the default locale used by I18n for the method + * {@link I18n#_(String, Object...)}. * + * <p/> + * As a side effect, it will also set this locale is the default locale in + * the system (says the method {@link Locale#getDefault()} will return the + * given locale). + * <p/> + * <b>Note :</b> The I18n system must have been initialized by one of the + * {@code init} method. * - * @param locale la locale dans lequel on souhaite la traduction - * @param message la chaine a traduire - * @return la traduction si possible ou la chaine passee en parametre - * sinon. + * @param locale the new default locale. + * @throws IllegalStateException if I18n was not init * @since 2.1 */ - public static String l_(Locale locale, String message) { + public static void setDefaultLocale(Locale locale) throws IllegalStateException { - // if the key to translate is null, just return null - if (message == null) { - return null; - } + checkInit(); - I18nLanguage language = getLanguage(locale); - String result = message; - if (language != null) { - result = language.translate(message); - } - return applyFilter(result); + store.setCurrentLocale(locale); } /** + * Obtain the default locale setted in I18n. This very locale is used in + * translation when no locale information is given + * (says in method {@link I18n#_(String, Object...)}. + * <p/> + * <b>Note :</b> The I18n system must have been initialized by one of the + * {@code init} method. + * + * @return the default locale initialized in I18n + * @throws IllegalStateException if I18n was not init + */ + public static Locale getDefaultLocale() throws IllegalStateException { + + checkInit(); + + Locale locale = store.getCurrentLocale(); + return locale; + } + + /** * Retourne la chaine traduite si possible dans la locale demandée. * * @param locale la locale dans lequel on souhaite la traduction @@ -167,16 +278,22 @@ */ public static String l_(Locale locale, String message, Object... args) { + checkInit(); + // if the key to translate is null, just return null if (message == null) { return null; } I18nLanguage language = getLanguage(locale); - String result = message; - if (language != null) { - result = language.translate(message); + String result = language.translate(message); + + if (args.length == 0) { + + // no argument form translation + return applyFilter(result); } + try { return applyFilter(String.format(result, args)); } catch (Exception eee) { @@ -199,20 +316,13 @@ * @param message la chaine a traduire * @return la traduction si possible ou la chaine passee en parametre * sinon. + * @deprecated since 2.1, will be removed in version 3.0, use instead the + * method {@link I18n#_(String, Object...)}. */ + @Deprecated public static String _(String message) { - // if the key to translate is null, just return null - if (message == null) { - return null; - } - - // get current locale (from the language in the store) - Locale locale = getCurrentLanguage().getLocale(); - - // translate with this locale - String result = l_(locale, message); - return result; + return _(message, EMPTY_OBJECT_ARRAY); } /** @@ -232,7 +342,7 @@ } // get current locale (from the language in the store) - Locale locale = getCurrentLanguage().getLocale(); + Locale locale = getDefaultLocale(); // translate with this locale String result = l_(locale, message, args); @@ -261,6 +371,10 @@ * @return le message passe en argument mais formatté avec les parametres */ public static String n_(String message, Object... args) { + if (args.length == 0) { + return message; + } + try { return String.format(message, args); } catch (Exception eee) { @@ -291,9 +405,12 @@ * * @param message la chaine à traduire * @return la chaine passée en argument. + * @deprecated since 2.1, will be removed in version 3.0, use instead the + * method {@link I18n#n_(String, Object...)}. */ + @Deprecated public static String n_(String message) { - return message; + return n_(message, EMPTY_OBJECT_ARRAY); } /** @@ -315,11 +432,15 @@ * If no one was specified, then use the {@link ClassPathI18nInitializer}. * * @return the i81n initializer to used to init system + * @deprecated since 2.1, will be removed in version 3.0, the initializer + * will no more be saved in this class but directly in the + * {@link I18nStore}. */ + @Deprecated public static I18nInitializer getInitializer() { - if (initializer == null) { - initializer = new ClassPathI18nInitializer(); - } +// if (initializer == null) { +// initializer = new ClassPathI18nInitializer(); +// } return initializer; } @@ -331,9 +452,9 @@ * @return the instanciated i18n store */ public static I18nStore getStore() { - if (store == null) { - store = new I18nStore(DEFAULT_LOCALE, getInitializer()); - } +// if (store == null) { +// store = new I18nStore(DEFAULT_LOCALE, getInitializer()); +// } return store; } @@ -361,7 +482,6 @@ * not init. */ protected static I18nLanguage getCurrentLanguage() { -// I18nLanguage language = getStore().getLanguage(); I18nLanguage language = getLanguage(null); return language; } @@ -381,28 +501,26 @@ * @since 2.1 */ protected static I18nLanguage getLanguage(Locale locale) { + + checkInit(); + I18nLanguage language; if (locale == null) { // default locale required : means wants the one of the store - language = getStore().getLanguage(); + locale = getDefaultLocale(); - if (language == null) { + if (locale == null) { - // store was not initialized + // no locale registed in store, use the default locale from store + locale = store.getDefaultLocale(); + } + } - // use the default locale of the store - locale = getStore().getDefaultLocale(); + // get the given language from the store + language = store.getLanguage(locale); - // get the language for this default locale - language = getStore().getLanguage(locale); - } - } else { - - // get the given language from the store - language = getStore().getLanguage(locale); - } return language; } @@ -410,4 +528,51 @@ return filter; } + protected static void initStore(I18nInitializer initializer, + Locale locale) throws NullPointerException { + + if (initializer == null) { + throw new NullPointerException( + "initializer parameter can not be null"); + } + + if (locale == null) { + throw new NullPointerException( + "locale parameter can not be null"); + } + + if (store != null) { + store.close(); + store = null; + } + store = new I18nStore(locale, initializer); + + setDefaultLocale(locale); + } + + protected static I18nInitializer getDefaultInitializer() { + + I18nInitializer initializer; + + // will be removed in version 3.0 + if (I18n.initializer != null) { + initializer = I18n.initializer; + } else { + initializer = new ClassPathI18nInitializer(); + } + return initializer; + } + + /** + * Checks if the I18n was initialized. + * + * @throws IllegalStateException if I18n was not initialized + * @since 2.1 + */ + protected static void checkInit() throws IllegalStateException { + if (store == null) { + throw new IllegalStateException("I18n was not initialized!"); + } + } + } Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nStore.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nStore.java 2011-01-20 15:17:58 UTC (rev 1851) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nStore.java 2011-01-21 10:13:01 UTC (rev 1852) @@ -25,6 +25,7 @@ package org.nuiton.i18n; +import org.apache.commons.collections.MapUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.i18n.bundle.I18nBundle; @@ -32,9 +33,10 @@ import org.nuiton.i18n.bundle.I18nBundleUtil; import org.nuiton.i18n.init.I18nInitializer; -import java.util.ArrayList; -import java.util.List; +import java.util.Collection; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; /** * Represents the store of languages of the i18n system. @@ -54,35 +56,98 @@ protected I18nLanguage language; /** le cache de languages deja charges */ - protected List<I18nLanguage> languages; + protected Map<Locale, I18nLanguage> languages; /** le cache de bundles deja charges */ protected I18nBundle[] bundles; - /** la locale par defaut a utiliser */ + /** la locale par defaut a utiliser. */ protected Locale defaultLocale; /** le resolver de bundles */ protected I18nInitializer resolver; + /** + * @param defaultLocale default locale + * @param resolver resolver of bundles + */ public I18nStore(Locale defaultLocale, I18nInitializer resolver) { - this.defaultLocale = defaultLocale; + this.defaultLocale = defaultLocale == null ? Locale.getDefault() : defaultLocale; this.resolver = resolver; } - /** @return current language loaded or null, if no language was load */ - public I18nLanguage getLanguage() { + /** + * Obtain the current language setted in the store. + * <p/> + * This language is used for all translations without locale information + * (says the method {@link I18n#_(String, Object...)}). + * + * @return the current language or {@code null} if none is defined + * @since 2.1 + */ + public I18nLanguage getCurrentLanguage() { return language; } - /** @return le cache de language avec instanciation paresseuse */ - public List<I18nLanguage> getLanguages() { - if (languages == null) { - languages = new ArrayList<I18nLanguage>(); + /** + * Obtain the current locale setted in the store. + * <p/> + * This locale is coming from the current language and is used for all + * translations without locale information (says the method {@link I18n#_(String, Object...)}. + * + * @return the current locale or {@code null} if no current language is setted + * @since 2.1 + */ + public Locale getCurrentLocale() { + return language == null ? null : language.getLocale(); + } + + /** + * Sets the current locale for the store. + * <p/> + * This will set the current language with this given locale. + * + * @param locale the new current locale + * @since 2.1 + */ + public void setCurrentLocale(Locale locale) { + Locale currentLocale = getCurrentLocale(); + if (locale.equals(currentLocale)) { + + // nothing to do, alreayd using this locale + return; } - return languages; + + // set the new current language + init(); + + if (log.isDebugEnabled()) { + log.debug("locale: " + locale); + } + I18nLanguage result = getLanguage(locale); + language = result; + //TC-20090702 the selected language is the default locale, usefull for + // objects dealing with the default locale (swing widgets,...) + Locale.setDefault(locale); } + /** + * @return current language loaded or null, if no language was load. + * @deprecated since 2.1, will be removed in version 3.0, prefer use now + * the method {@link #getCurrentLanguage()}. + */ + @Deprecated + public I18nLanguage getLanguage() { + return language; + } + + /** @return le cache de language actuellement pris en charge. */ + public I18nLanguage[] getLanguages() { + Collection<I18nLanguage> values = getLanguagesCache().values(); + return values.toArray(new I18nLanguage[values.size()]); + } + + /** @return the default locale of the store */ public Locale getDefaultLocale() { return defaultLocale; } @@ -150,7 +215,10 @@ * Set a new language in store, given a locale. * * @param locale la locale du language requis + * @deprecated since 2.1, will be removed in version 3.0, use now the + * method {@link #setCurrentLocale(Locale)}. */ + @Deprecated protected void setLanguage(Locale locale) { init(); if (log.isDebugEnabled()) { @@ -173,7 +241,7 @@ if (log.isInfoEnabled()) { log.info("will close " + languages.size() + " language(s)."); } - for (I18nLanguage l : languages) { + for (I18nLanguage l : languages.values()) { l.close(); } languages.clear(); @@ -185,10 +253,18 @@ language = null; } + /** @return le cache de language avec instanciation paresseuse */ + protected Map<Locale, I18nLanguage> getLanguagesCache() { + if (languages == null) { + languages = new HashMap<Locale, I18nLanguage>(); + } + return languages; + } + /** * Recherche un object de type {@link I18nLanguage} pour la locale donnée * en paramètre dans le cache des langues chargées ({@link #languages}). - * + * <p/> * Si un tel objet n'existe pas, alors on en crée un et on le place dans le * cache. * @@ -196,23 +272,20 @@ * @return le language trouve dans le cache. */ protected I18nLanguage getLanguage(Locale locale) { + I18nLanguage result = null; - if (!(languages == null || languages.isEmpty())) { - for (I18nLanguage l : languages) { - if (locale.equals(l.getLocale())) { - result = l; - break; - } - } + + if (MapUtils.isNotEmpty(languages)) { + + // take the already registred language + result = languages.get(locale); } if (result == null) { - if (!isInit()) { - // always init the store - init(); - } + // add a new language for the given locale result = addLanguage(locale); + } else { if (log.isDebugEnabled()) { log.debug("using cached language : " + result); @@ -223,6 +296,13 @@ } protected I18nLanguage addLanguage(Locale locale) { + + if (!isInit()) { + + // always init the store + init(); + } + I18nLanguage result; result = new I18nLanguage(locale); I18nBundleEntry[] entries = getBundleEntries(locale); @@ -232,7 +312,7 @@ log.info(result + ", nbEntries: " + entries.length + ", nbSentences: " + result.size() + "."); } - getLanguages().add(result); + getLanguagesCache().put(locale, result); return result; } @@ -246,4 +326,8 @@ "should call init method on " + I18nStore.class); } } + + public I18nInitializer getResolver() { + return resolver; + } } Modified: trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nStoreTest.java =================================================================== --- trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nStoreTest.java 2011-01-20 15:17:58 UTC (rev 1851) +++ trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nStoreTest.java 2011-01-21 10:13:01 UTC (rev 1852) @@ -25,13 +25,12 @@ package org.nuiton.i18n; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.i18n.init.DefaultI18nInitializer; -import java.net.MalformedURLException; import java.util.Locale; /** @@ -50,16 +49,18 @@ I18nStore store; + + static DefaultI18nInitializer initializer; + @BeforeClass public static void beforeClass() { - I18n.setInitializer( - new DefaultI18nInitializer(I18nStoreTest.class.getSimpleName()) - ); + + initializer = new DefaultI18nInitializer( + I18nStoreTest.class.getSimpleName()); } - @AfterClass - public static void afterClass() throws Exception { - I18n.setInitializer(null); + @After + public void after() throws Exception { I18n.close(); } @@ -69,16 +70,23 @@ Assert.assertNull(I18n.store); store = I18n.getStore(); + Assert.assertNull(I18n.store); + + I18n.init(initializer, null); + + store = I18n.getStore(); + Assert.assertNotNull(store); //assertEquals(I18n.DEFAULT_ENCODING, store.getEncoding()); - Assert.assertNull(store.getLanguage()); + Assert.assertNotNull(store.getCurrentLanguage()); } @Test public void testChangeLocale() throws Exception { - locale = I18nUtil.newLocale("fr_FR"); - encoding = I18n.ISO_8859_1_ENCONDING; + I18n.init(initializer, locale = I18nUtil.newLocale("fr_FR")); +// locale = I18nUtil.newLocale("fr_FR"); +// encoding = I18n.ISO_8859_1_ENCONDING; updateLanguage(); assertNbLanguages(1); updateLanguage(); @@ -101,39 +109,17 @@ } protected void assertLanguageChanged() { - Assert.assertNotSame(language, store.getLanguage()); + Assert.assertNotSame(language, store.getCurrentLanguage()); } - /*public void testChangeEncoding() throws Exception { - locale = I18n.newLocale("fr_FR"); - encoding = I18n.ISO_8859_1_ENCONDING; - updateLanguage(); - - locale = I18n.newLocale("en_GB"); - updateLanguage(); - - // language change (from his encoding) - assertLanguageChanged(); - // 2 language in cache - assertNbLanguages(2); - - encoding = I18n.UTF_8_ENCONDING; - updateLanguage(); - // language change (from his encoding) - assertLanguageChanged(); - // one language in cache - assertNbLanguages(1); - - }*/ - protected void assertNbLanguages(int i) { - Assert.assertEquals(i, store.getLanguages().size()); + Assert.assertEquals(i, store.getLanguages().length); } protected void updateLanguage() { - language = store == null ? null : store.getLanguage(); + language = store == null ? null : store.getCurrentLanguage(); store = I18n.getStore(); - store.setLanguage(locale); + store.setCurrentLocale(locale); } } Modified: trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java =================================================================== --- trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java 2011-01-20 15:17:58 UTC (rev 1851) +++ trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java 2011-01-21 10:13:01 UTC (rev 1852) @@ -25,7 +25,6 @@ package org.nuiton.i18n; import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -41,11 +40,13 @@ */ public class I18nTest { + static DefaultI18nInitializer initializer; + @BeforeClass public static void beforeClass() { - I18n.setInitializer( - new DefaultI18nInitializer(I18nStoreTest.class.getSimpleName()) - ); + + initializer = new DefaultI18nInitializer( + I18nStoreTest.class.getSimpleName()); } @After @@ -53,24 +54,35 @@ I18n.close(); } - @AfterClass - public static void afterClass() throws Exception { - I18n.setInitializer(null); - I18n.close(); + @Test(expected = IllegalStateException.class) + public void testWithNoInit() { + + I18n._("key.with.param"); } + @Test(expected = IllegalStateException.class) + public void testWithNoInit2() { + + I18n.l_(Locale.FRANCE, "key.with.param"); + } + + @Test - public void testWithNoInit() { + public void testDefaultInit() { + String expected; String actual; - String expected; - actual = I18n._("key.with.param"); - Assert.assertNotNull(actual); + Assert.assertNull(I18n.store); - expected = "Clef avec %s"; - actual = I18n.l_(Locale.FRANCE, "key.with.param"); - Assert.assertEquals(expected, actual); + I18n.init(); + + Assert.assertNotNull(I18n.store); + Assert.assertNotNull(I18n.getDefaultLocale()); + Assert.assertEquals(Locale.getDefault(), I18n.getDefaultLocale()); + Assert.assertNotNull(I18n.store.getLanguage()); + Assert.assertEquals(Locale.getDefault(), I18n.store.getLanguage().getLocale()); + } @Test @@ -81,7 +93,8 @@ // passage en français - I18n.getStore().setLanguage(Locale.FRANCE); + I18n.init(initializer, Locale.FRANCE); +// I18n.getStore().setLanguage(Locale.FRANCE); expected = "Clef avec %s"; actual = I18n._("key.with.param"); @@ -93,7 +106,8 @@ // passage en anglais - I18n.getStore().setLanguage(Locale.UK); + I18n.setDefaultLocale(Locale.UK); +// I18n.getStore().setLanguage(Locale.UK); expected = "Key with %s"; actual = I18n._("key.with.param"); @@ -105,7 +119,8 @@ // passage langue inconnue - I18n.getStore().setLanguage(Locale.CHINA); + I18n.setDefaultLocale(Locale.CHINA); +// I18n.getStore().setLanguage(Locale.CHINA); expected = "key.with.param"; actual = I18n._("key.with.param"); @@ -124,6 +139,8 @@ // en français + I18n.init(initializer, null); + expected = "Clef avec %s"; actual = I18n.l_(Locale.FRANCE, "key.with.param"); Assert.assertEquals(expected, actual); @@ -134,7 +151,7 @@ // en anglais - I18n.getStore().setLanguage(Locale.UK); +// I18n.getStore().setLanguage(Locale.UK); expected = "Key with %s"; actual = I18n.l_(Locale.UK, "key.with.param"); Modified: trunk/src/site/apt/index.apt =================================================================== --- trunk/src/site/apt/index.apt 2011-01-20 15:17:58 UTC (rev 1851) +++ trunk/src/site/apt/index.apt 2011-01-21 10:13:01 UTC (rev 1852) @@ -38,7 +38,7 @@ Petit exemple qui démontre la simplicité d'utilisation de Nuiton I18n : -------------------------------------------------------------------------------- -I18n.init(Locale.FR); +I18n.init(Locale.UK); System.out.println(I18n._("This text will be translated")); --------------------------------------------------------------------------------