r1922 - in trunk/nuiton-i18n/src: main/java/org/nuiton/i18n main/java/org/nuiton/i18n/bundle main/java/org/nuiton/i18n/init test/java/org/nuiton/i18n test/resources
Author: tchemit Date: 2011-05-11 16:51:07 +0200 (Wed, 11 May 2011) New Revision: 1922 Url: http://nuiton.org/repositories/revision/i18n/1922 Log: clean api Added: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nMessageFormatter.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/format/ Removed: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormat.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormatter.java Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nLanguage.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/DefaultI18nInitializer.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/I18nInitializer.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/UserI18nInitializer.java trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java trunk/nuiton-i18n/src/test/resources/log4j.properties Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -74,11 +74,15 @@ protected static I18nFilter filter; /** - * Formatter to use, default value is {@link I18nFormat#STRING_FORMAT} + * Formatter to apply on each translation. + * <p/> + * This formatter can not be configured directly here, but must be setted + * into the {@code initializer} used to configure the I18n system. * + * @see I18nInitializer#setMessageFormatter(I18nMessageFormatter) * @since 2.4 */ - protected static I18nFormatter formatter = I18nFormat.STRING_FORMAT; + protected static I18nMessageFormatter messageFormatter; /** * Change le filtre des chaines traduites @@ -90,16 +94,6 @@ } /** - * Change {@code formatter} to use on each translation with args. - * - * @param formatter I18nFormatter to use - * @since 2.4 - */ - public static void setFormatter(I18nFormatter formatter) { - I18n.formatter = formatter; - } - - /** * Initialize I18n system. * <p/> * The {@code initializer} can be null, in that case it will use the default @@ -199,7 +193,7 @@ * Retourne la chaine traduite si possible dans la locale demandée. * * @param locale la locale dans lequel on souhaite la traduction - * @param message message formate avec {@link I18nFormatter} + * @param message message formate avec {@link I18nMessageFormatter} * @param args les parametres pour le message. * @return la traduction si possible ou la chaine passee en parametre * sinon. @@ -217,7 +211,7 @@ I18nLanguage language = getLanguage(locale); String result = language.translate(message); - // Don't check the length, this will be done directly in formatter if necessary. + // Don't check the length, this will be done directly in messageFormatter if necessary. // In MessageFormat case it must format all messages even there is no args (because of '' escape case). // if (args.length == 0) { // @@ -226,10 +220,10 @@ // } try { - return applyFilter(formatter.format(locale, result, args)); + return applyFilter(messageFormatter.format(locale, result, args)); } catch (Exception eee) { try { - return applyFilter(formatter.format(locale, message, args)); + return applyFilter(messageFormatter.format(locale, message, args)); } catch (Exception zzz) { if (log.isWarnEnabled()) { log.warn( @@ -244,7 +238,7 @@ /** * Retourne la chaine traduite si possible. * - * @param message message formate avec {@link I18nFormatter} + * @param message message formate avec {@link I18nMessageFormatter} * @param args les parametres pour le message. * @return la traduction si possible ou la chaine passee en parametre * sinon. @@ -280,7 +274,7 @@ * devant être traduit seulement à leur lecture suivant la locale du lecteur * et non du créateur. * - * @param message message formate avec {@link I18nFormatter} + * @param message message formate avec {@link I18nMessageFormatter} * @param args les parametres pour le message. * @return le message passe en argument mais formatté avec les parametres */ @@ -293,7 +287,7 @@ // XXX-fdesbois-2011-05-05 : don't know if it's relevant to format here, // seems pretty useless because we will not use the value // corresponding to given key message - return formatter.format(getDefaultLocale(), message, args); + return messageFormatter.format(getDefaultLocale(), message, args); } catch (Exception eee) { if (log.isWarnEnabled()) { log.warn( @@ -315,6 +309,9 @@ store.close(); store = null; } + if (messageFormatter != null) { + messageFormatter = null; + } } /** @@ -398,8 +395,8 @@ return filter; } - public static I18nFormatter getFormatter() { - return formatter; + public static I18nMessageFormatter getMessageFormatter() { + return messageFormatter; } /** @@ -433,6 +430,8 @@ store = new I18nStore(locale, initializer); setDefaultLocale(locale); + + messageFormatter = initializer.getMessageFormatter(); } protected static I18nInitializer getDefaultInitializer() { Deleted: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormat.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormat.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormat.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -1,76 +0,0 @@ -/* - * #%L - * I18n :: Api - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2011 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.i18n; - -import java.text.MessageFormat; -import java.util.Formatter; -import java.util.Locale; - -/** - * Enum implementation for {@link I18nFormatter}. Provides basic formatter - * such as {@link #STRING_FORMAT} and {@link #MESSAGE_FORMAT}. - * <p/> - * Created: 05/05/11 - * - * @author fdesbois <desbois@codelutin.com> - * $Id$ - * @since 2.4 - */ -public enum I18nFormat implements I18nFormatter { - - /** - * Implementation based on printf syntax. - * - * @see Formatter - * @see String#format(Locale, String, Object...) - */ - STRING_FORMAT { - - @Override - public String format(Locale locale, String message, Object... args) { - String result; - // Previous behavior, no format will be done for empty args - if (args.length == 0) { - result = message; - } else { - result = String.format(locale, message, args); - } - return result; - } - }, - - /** - * Implementation based on {@link MessageFormat} syntax. - */ - MESSAGE_FORMAT { - - @Override - public String format(Locale locale, String message, Object... args) { - MessageFormat formatter = new MessageFormat(message, locale); - return formatter.format(args); - } - } - -} Deleted: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormatter.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormatter.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormatter.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -1,53 +0,0 @@ -/* - * #%L - * I18n :: Api - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2011 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.i18n; - -import java.util.Locale; - -/** - * Formatter to use at runtime when message need to be translated with args. - * <p/> - * Created: 05/05/11 - * - * @author fdesbois <desbois@codelutin.com> - * @see I18nFormat - * $Id$ - * @since 2.4 - */ -public interface I18nFormatter { - - /** - * Format a given {@code message} with {@code locale} and {@code args}. - * The purpose is to replace placeholders in {@code message} with {@code args} - * value. This could depends on {@code locale} for date purpose for example. - * - * @param locale Locale to use for formatting (number, date, ...) - * @param message Message to format (that contains placeholders) - * @param args Object array to use in formatting the message - * @return the formatted message - */ - String format(Locale locale, String message, Object... args); - -} Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nLanguage.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nLanguage.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nLanguage.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -81,8 +81,7 @@ */ @Deprecated public void load(I18nBundleEntry[] bundleEntries) { - Charset encoding = Charset.forName(I18nUtil.DEFAULT_ENCODING); - load(bundleEntries, encoding); + load(bundleEntries, I18nUtil.DEFAULT_CHARSET); } /** Copied: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nMessageFormatter.java (from rev 1920, trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFormatter.java) =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nMessageFormatter.java (rev 0) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nMessageFormatter.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -0,0 +1,57 @@ +/* + * #%L + * I18n :: Api + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2011 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.i18n; + +import java.util.Locale; + +/** + * Contract to format a i18n message. + * <p/> + * Created: 05/05/11 + * + * @author fdesbois <desbois@codelutin.com> + * @author tchemit <chemit@codelutin.com> + * @see I18nUtil.DefaultI18nMessageFormatters + * $Id$ + * @since 2.4 + */ +public interface I18nMessageFormatter { + + /** + * Format a given {@code message} with {@code locale} and optinal {@code args}. + * <p/> + * The main purpose is to replace placeholders in {@code message} with + * {@code args} value. + * <p/> + * This may depend on {@code locale} for date purpose for example. + * + * @param locale locale to use for formatting (number, date, ...) + * @param message message to format (that contains placeholders) + * @param args object array to use in formatting the message + * @return the formatted message + */ + String format(Locale locale, String message, Object... args); + +} Property changes on: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nMessageFormatter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -36,8 +36,11 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Formatter; import java.util.List; import java.util.Locale; import java.util.Stack; @@ -49,7 +52,7 @@ /** @author tchemit <chemit@codelutin.com> */ public class I18nUtil { - /** to use log facility, just put in your code: log.info(\"...\"); */ + /** Logger. */ private static final Log log = LogFactory.getLog(I18nUtil.class); public static final String ISO_8859_1_ENCONDING = "ISO-8859-1"; @@ -58,6 +61,12 @@ public static final String DEFAULT_ENCODING = UTF_8_ENCONDING; + public static final Charset DEFAULT_CHARSET = + Charset.forName(DEFAULT_ENCODING); + + public static final I18nMessageFormatter DEFAULT_MESSAGE_FORMATTER = + new StringFormatI18nMessageFormatter(); + public static final Locale DEFAULT_LOCALE = Locale.UK; public static final String[] EMPTY_STRING_ARRAY = new String[0]; @@ -83,7 +92,7 @@ result.add(l); } catch (Exception e) { throw new IllegalArgumentException("bundle " + s + - " is not a valid locale,e"); + " is not a valid locale", e); } } return result.toArray(new Locale[result.size()]); @@ -91,15 +100,18 @@ public static Locale newLocale(String str) { if (str == null) { - // get use locale + + // get user locale return newLocale(null, null); } try { return (Locale) new LocaleConverter().convert(Locale.class, str); } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("could not load locale '" + str + " for reason : " + e.getMessage()); - } + if (log.isWarnEnabled()) { + log.warn("could not load locale '" + str + + " for reason : " + e.getMessage()); + } + // use default locale return DEFAULT_LOCALE; } @@ -107,6 +119,7 @@ public static Locale newLocale(String language, String country) { if (language == null) { + // get user locale language = System.getProperty("user.language", DEFAULT_LOCALE.getLanguage()); @@ -378,4 +391,46 @@ } return result; } + + /** + * Implementation of {@link I18nMessageFormatter} based on {@link Formatter} + * syntax. + * <p/> + * <strong>Note: </strong> This is the default message formatter used by + * i18n system. + * + * @see Formatter + * @see String#format(Locale, String, Object...) + * @since 2.4 + */ + public static class StringFormatI18nMessageFormatter implements I18nMessageFormatter { + + @Override + public String format(Locale locale, String message, Object... args) { + String result; + // Previous behavior, no format will be done for empty args + if (args.length == 0) { + result = message; + } else { + result = String.format(locale, message, args); + } + return result; + } + } + + /** + * Implementation of {@link I18nMessageFormatter} based on + * {@link MessageFormat} syntax. + * + * @see MessageFormat + * @since 2.4 + */ + public static class MessageFormatI18nMessageFormatter implements I18nMessageFormatter { + @Override + public String format(Locale locale, String message, Object... args) { + MessageFormat formatter = new MessageFormat(message, locale); + return formatter.format(args); + } + } + } Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleEntry.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -130,8 +130,7 @@ */ @Deprecated public void load(Properties resource) throws IOException { - Charset encoding = Charset.forName(I18nUtil.DEFAULT_ENCODING); - load(resource, encoding); + load(resource, I18nUtil.DEFAULT_CHARSET); } /** Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -33,7 +33,6 @@ import java.net.URL; import java.net.URLClassLoader; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -71,11 +70,6 @@ } public ClassPathI18nInitializer(ClassLoader loader, URL[] extraURLs) { - this(loader, extraURLs, null); - } - - public ClassPathI18nInitializer(ClassLoader loader, URL[] extraURLs, Charset encoding) { - super(encoding); this.loader = loader == null ? getClass().getClassLoader() : loader; this.extraURLs = extraURLs; } Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/DefaultI18nInitializer.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/DefaultI18nInitializer.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/DefaultI18nInitializer.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -78,13 +78,13 @@ public static final String DEFAULT_I18N_PATH = "META-INF/"; public DefaultI18nInitializer(String bundleName) throws - NullPointerException { + NullPointerException { this(bundleName, null, null); } public DefaultI18nInitializer(String bundleName, ClassLoader loader) throws - NullPointerException { + NullPointerException { this(bundleName, loader, null); } @@ -148,11 +148,12 @@ } // Load encoding from definition file and use it as Charset encoding - if (encoding == null) { - String encoding = properties.getProperty(BUNDLE_DEF_ENCODING); - Charset charset = Charset.forName(encoding); - setEncoding(charset); + String encoding = properties.getProperty(BUNDLE_DEF_ENCODING); + Charset charset = Charset.forName(encoding); + if (log.isInfoEnabled()) { + log.info("Use encoding " + charset); } + setEncoding(charset); String prefix = url.toString(); prefix = prefix.substring(0, prefix.length() - filename.length()); Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/I18nInitializer.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/I18nInitializer.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/I18nInitializer.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -27,6 +27,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.i18n.I18n; +import org.nuiton.i18n.I18nMessageFormatter; import org.nuiton.i18n.I18nUtil; import org.nuiton.i18n.bundle.I18nBundle; import org.nuiton.i18n.bundle.I18nBundleEntry; @@ -37,7 +39,8 @@ import java.util.List; /** - * Contract of a resolver of {@link I18nBundle}. + * Abstract object to resolv {@link I18nBundle} and prepare initialization of + * {@link I18n}. * * @author tchemit <chemit@codelutin.com> * @since 1.1 @@ -47,21 +50,28 @@ /** Logger */ private static final Log log = LogFactory.getLog(I18nInitializer.class); - protected static Charset defaultEncoding = - Charset.forName(I18nUtil.DEFAULT_ENCODING); - + /** + * Encoding used to load i18n bundles. + * + * @since 2.4 + */ protected Charset encoding; - protected I18nInitializer() { - } - /** - * Constructor with {@code encoding} used to load Properties file. + * Message formatter used in {@link I18n} to produce final translated + * messages. * - * @param encoding Charset to use for Properties loading + * @since 2.4 */ - protected I18nInitializer(Charset encoding) { - this.encoding = encoding; + protected I18nMessageFormatter messageFormatter; + + protected I18nInitializer() { + + // use the default encoding + setEncoding(I18nUtil.DEFAULT_CHARSET); + + // use the default message formatter + setMessageFormatter(I18nUtil.DEFAULT_MESSAGE_FORMATTER); } /** @@ -86,17 +96,29 @@ log.info(bundles.size() + " bundle(s) found, in " + entries.length + " file(s)."); } - return result; } public Charset getEncoding() { - Charset result = encoding == null ? defaultEncoding : encoding; - return result; + return encoding; } public void setEncoding(Charset encoding) { + if (encoding == null) { + throw new NullPointerException("Can not set a null encoding"); + } this.encoding = encoding; } + public I18nMessageFormatter getMessageFormatter() { + return messageFormatter; + } + + public void setMessageFormatter(I18nMessageFormatter messageFormatter) { + if (messageFormatter == null) { + throw new NullPointerException( + "Can not set a null message formatter"); + } + this.messageFormatter = messageFormatter; + } } Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/UserI18nInitializer.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/UserI18nInitializer.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/UserI18nInitializer.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -28,6 +28,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.i18n.I18nMessageFormatter; import org.nuiton.i18n.bundle.I18nBundle; import org.nuiton.i18n.bundle.I18nBundleEntry; import org.nuiton.i18n.bundle.I18nBundleUtil; @@ -37,6 +38,7 @@ import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.Charset; import java.util.Properties; /** @@ -97,6 +99,26 @@ } @Override + public Charset getEncoding() { + return getDelegate().getEncoding(); + } + + @Override + public void setEncoding(Charset encoding) { + getDelegate().setEncoding(encoding); + } + + @Override + public I18nMessageFormatter getMessageFormatter() { + return getDelegate().getMessageFormatter(); + } + + @Override + public void setMessageFormatter(I18nMessageFormatter messageFormatter) { + getDelegate().setMessageFormatter(messageFormatter); + } + + @Override public I18nBundle[] resolvBundles() throws Exception { File directory = getUserDirectory(); @@ -164,8 +186,7 @@ I18nBundle[] bundles = resolvBundles(urls); // detect bundles entries - I18nBundleEntry[] entries = - I18nBundleUtil.getBundleEntries(bundles); + I18nBundleEntry[] entries = I18nBundleUtil.getBundleEntries(bundles); // copy all bundle entries resource for (I18nBundleEntry e : entries) { Modified: trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java =================================================================== --- trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java 2011-05-11 14:51:07 UTC (rev 1922) @@ -79,7 +79,7 @@ String actual; // pas de traduction possible car l'initialiser n'est pas bon :) - + expected = "key.with.param"; actual = I18n.l_(Locale.FRANCE, "key.with.param"); Assert.assertEquals(expected, actual); @@ -204,8 +204,8 @@ @Test public void testFormatterMessageFormat() { + initializer.setMessageFormatter(new I18nUtil.MessageFormatI18nMessageFormatter()); I18n.init(initializer, Locale.UK); - I18n.setFormatter(I18nFormat.MESSAGE_FORMAT); Date date = new GregorianCalendar(2011, 4, 5).getTime(); @@ -220,8 +220,5 @@ expected = "Clé avec 5 mai 2011"; actual = I18n.l_(Locale.FRANCE, "key.with.date", date); Assert.assertEquals(expected, actual); - - // reset default value - I18n.setFormatter(I18nFormat.STRING_FORMAT); } } Modified: trunk/nuiton-i18n/src/test/resources/log4j.properties =================================================================== --- trunk/nuiton-i18n/src/test/resources/log4j.properties 2011-05-11 14:48:59 UTC (rev 1921) +++ trunk/nuiton-i18n/src/test/resources/log4j.properties 2011-05-11 14:51:07 UTC (rev 1922) @@ -28,6 +28,6 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n -#log4j.appender.stdout.layout.ConversionPattern=%%c=%c %%C=%C %%d=%d %%F=%F %%l=%l %%L=%L %%m=%m %%M=%M %%p=%p %%r=%r %%t=%t %%x=%x %%X=%X + # package level -log4j.logger.org.nuiton.i18n=INFO +log4j.logger.org.nuiton=WARN
participants (1)
-
tchemit@users.nuiton.org