r1844 - in trunk/nuiton-i18n/src: main/java/org/nuiton/i18n main/java/org/nuiton/i18n/bundle main/java/org/nuiton/i18n/init main/java/org/nuiton/util test/java/org/nuiton/i18n test/java/org/nuiton/util test/java/org/nuiton/util/converter test/resources/META-INF
Author: tchemit Date: 2011-01-19 22:38:53 +0100 (Wed, 19 Jan 2011) New Revision: 1844 Url: http://nuiton.org/repositories/revision/i18n/1844 Log: Evolution #1210: Remove deprecated api Evolution #1208: Be able to force locale for translation (add some tests) Added: trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java trunk/nuiton-i18n/src/test/java/org/nuiton/util/converter/ trunk/nuiton-i18n/src/test/java/org/nuiton/util/converter/LocaleConverterTest.java Removed: trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java trunk/nuiton-i18n/src/test/java/org/nuiton/util/LocaleConverterTest.java Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFilter.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nStore.java trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.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/UserI18nInitializer.java trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nStoreTest.java trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_en_GB.properties trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_fr_FR.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-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18n.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -128,12 +128,13 @@ } /** - * Retourne la chaine traduite si possible. + * Retourne la chaine traduite si possible dans la locale demandée. * * @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. + * @since 2.1 */ public static String l_(Locale locale, String message) { @@ -150,14 +151,16 @@ return applyFilter(result); } - /** - * Retourne la chaine traduite si possible. + /** + * 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 la meme syntaxe que {@link * String#format} * @param args les parametres pour le message. * @return la traduction si possible ou la chaine passee en parametre * sinon. + * @since 2.1 */ public static String l_(Locale locale, String message, Object... args) { @@ -273,7 +276,7 @@ } /** - * close i18n caches, says the store if exists + * Close i18n caches, says the store if exists. * <p/> * This method should be called to reset all caches (languages, * bundles,...) @@ -335,49 +338,4 @@ return filter; } - /** - * @return the current store - * @deprecated since 1.1, only keep for compatibility - */ - @Deprecated - public static I18nStore getLoader() { - return getStore(); - } - - /** - * Parse a list of {@link Locale} seperated by comma. - * <p/> - * Example : fr_FR,en_GB - * - * @param str the string representation of locale separated by comma - * @return list of available locales - * @throws IllegalArgumentException ia a locale is not valid - * @deprecated since 1.1, prefer use the {@link I18nUtil#parseLocales(String)} - */ - @Deprecated - public static Locale[] parseLocales(String str) - throws IllegalArgumentException { - return I18nUtil.parseLocales(str); - } - - /** - * @param str the text representation of the locale - * @return the locale, or default locale if could not parse the given one - * @deprecated since 1.1, prefer use the {@link I18nUtil#newLocale(String)} - */ - @Deprecated - public static Locale newLocale(String str) { - return I18nUtil.newLocale(str); - } - - /** - * @param language the language of the locale - * @param country the country of the locale - * @return the required locale - * @deprecated since 1.1, prefer use the {@link I18nUtil#newLocale(String,String)} - */ - @Deprecated - public static Locale newLocale(String language, String country) { - return I18nUtil.newLocale(language, country); - } } Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFilter.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFilter.java 2011-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nFilter.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -23,7 +23,7 @@ * #L% */ -/* * +/** * i18nFilter.java * * Created: 2 déc. 2003 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-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nStore.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -158,7 +158,7 @@ } I18nLanguage result = getLanguage(locale); language = result; - //TC-20090702 the selected langue is the default locale, usefull for + //TC-20090702 the selected language is the default locale, usefull for // objects dealing with the default locale (swing widgets,...) Locale.setDefault(locale); } @@ -166,7 +166,7 @@ /** * Close store and release cache ofg language. * <p/> - * Current language will be also clean. + * Current language will be also cleaned. */ protected void close() { if (languages != null) { @@ -186,8 +186,14 @@ } /** + * Recherche un object de type {@link I18nLanguage} pour la locale donnée + * en paramètre dans le cache des langues chargées ({@link #languages}). + * + * Si un tel objet n'existe pas, alors on en crée un et on le place dans le + * cache. + * * @param locale la locale du language recherche - * @return le language trouve dans le cache, ou null. + * @return le language trouve dans le cache. */ protected I18nLanguage getLanguage(Locale locale) { I18nLanguage result = null; @@ -208,7 +214,6 @@ } } - return result; } Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java 2011-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/bundle/I18nBundleUtil.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -61,13 +61,6 @@ public static final String DIRECTORY_SEARCH_BUNDLE_PATTERN = "i18n"; - /** - * @deprecated since 2.0, this is not compatible with os, so do not used it - * any more. - */ - @Deprecated - public static final String SEARCH_BUNDLE_PATTERN = ".*i18n/.+\\.properties"; - private static final I18nBundleEntry[] EMPTY_I18N_BUNDLE_ENTRYS_ARRAY = new I18nBundleEntry[0]; 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-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/ClassPathI18nInitializer.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -116,12 +116,11 @@ @Override public I18nBundle[] resolvBundles() throws Exception { - // detect bundles urls + // detect bundles urls URL[] urls = resolvURLs(); // detect bundles - I18nBundle[] result = resolvBundles(urls); return result; } 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-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/DefaultI18nInitializer.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -162,10 +162,9 @@ return definitionURL; } -// @Override + public URL[] resolvURLs(String prefixURL, + Properties definition) throws Exception { - public URL[] resolvURLs(String prefixURL, Properties definition) throws Exception { - // get locales from properties String localesAsStr = definition.getProperty(BUNDLE_DEF_LOCALES); @@ -206,11 +205,9 @@ String prefixURL = resolvDefinition(definition); // detect bundles urls - URL[] urls = resolvURLs(prefixURL, definition); // detect bundles - I18nBundle[] result = resolvBundles(urls); return result; } 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-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/init/UserI18nInitializer.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -158,20 +158,16 @@ } // detect bundles urls - URL[] urls = resolvURLs(prefixURL, definition); // detect bundles - I18nBundle[] bundles = resolvBundles(urls); // detect bundles entries - I18nBundleEntry[] entries = I18nBundleUtil.getBundleEntries(bundles); // copy all bundle entries resource - for (I18nBundleEntry e : entries) { URL url = e.getPath(); @@ -190,8 +186,7 @@ log.info("Create user file to create : " + dst); } - // recopie du fichier - + // copy file outStream = new FileOutputStream(dst); try { IOUtils.copy(url.openStream(), outStream); Deleted: trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java =================================================================== --- trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java 2011-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -1,149 +0,0 @@ -/* - * #%L - * I18n :: Api - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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.util; - -import org.apache.commons.beanutils.ConversionException; -import org.apache.commons.beanutils.Converter; -import static org.apache.commons.logging.LogFactory.getLog; - -import org.apache.commons.logging.Log; -import org.nuiton.i18n.CountryEnum; -import org.nuiton.i18n.LanguageEnum; - -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * classe pour convertir une chaine en un objet {@link Locale}. - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 2.0.1, use the {@link org.nuiton.util.converter.LocaleConverter} instead - */ -@Deprecated -public class LocaleConverter implements Converter { - - private static final Pattern FULL_SCOPE_PATTERN = - Pattern.compile("([a-zA-Z]{2})_([a-zA-Z]{2})"); - - private static final Pattern MEDIUM_SCOPE_PATTERN = - Pattern.compile("([a-zA-Z]{2})"); - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static Log log = getLog(LocaleConverter.class); - - @Override - public Object convert(Class aClass, Object value) { - if (value == null) { - throw new ConversionException("can not convert null value in " + - this + " convertor"); - } - if (isEnabled(aClass)) { - Object result; - if (isEnabled(value.getClass())) { - result = value; - return result; - } - if (value instanceof String) { - result = valueOf(((String) value).trim()); - return result; - } - } - throw new ConversionException( - "could not find a convertor for type " + aClass.getName() + - " and value : " + value); - } - - public Locale valueOf(String value) { - try { - Locale result = convertFullScope(value); - - if (result == null) { - result = convertMediumScope(value); - } - - if (result == null) { - throw new ConversionException("could not convert locale " + - value); - } - - return result; - } catch (Exception e) { - throw new ConversionException("could not convert locale " + value + - " for reason " + e.getMessage()); - } - } - - private Locale convertFullScope(String value) { - Matcher m = FULL_SCOPE_PATTERN.matcher(value); - if (m.matches()) { - // found a full scope pattern (language + country) - LanguageEnum language = - LanguageEnum.valueOf(m.group(1).toLowerCase()); - CountryEnum country = CountryEnum.valueOf(m.group(2).toUpperCase()); - if (language == null || country == null) { - // not safe - throw new ConversionException("could not convert locale " + - value); - } - return new Locale(language.name(), country.name()); - } - return null; - } - - private Locale convertMediumScope(String value) { - Matcher m = MEDIUM_SCOPE_PATTERN.matcher(value); - if (m.matches()) { - // found a medium scope pattern (only language) - LanguageEnum language = - LanguageEnum.valueOf(m.group(1).toLowerCase()); - - if (language == null) { - // not safe - throw new ConversionException("could not convert locale " + - value); - } - return new Locale(language.name()); - } - return null; - } - - - public LocaleConverter() { - if (log.isDebugEnabled()) { - log.debug(this); - } - } - - protected boolean isEnabled(Class<?> aClass) { - return Locale.class.equals(aClass); - } - - public Class<?> getType() { - return Locale.class; - } - -} 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-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nStoreTest.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -51,7 +51,7 @@ I18nStore store; @BeforeClass - public static void beforeClass() throws MalformedURLException { + public static void beforeClass() { I18n.setInitializer( new DefaultI18nInitializer(I18nStoreTest.class.getSimpleName()) ); Added: trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java =================================================================== --- trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java (rev 0) +++ trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -0,0 +1,113 @@ +package org.nuiton.i18n; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.nuiton.i18n.init.DefaultI18nInitializer; + +import java.util.Locale; + +/** + * Test the class {@link I18n}. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.1 + */ +public class I18nTest { + + @BeforeClass + public static void beforeClass() { + I18n.setInitializer( + new DefaultI18nInitializer(I18nStoreTest.class.getSimpleName()) + ); + } + + @AfterClass + public static void afterClass() throws Exception { + I18n.setInitializer(null); + I18n.close(); + } + + @Test + public void testSimple() { + + String expected; + String actual; + + // passage en français + + I18n.getStore().setLanguage(Locale.FRANCE); + + expected = "Clef avec %s"; + actual = I18n._("key.with.param"); + Assert.assertEquals(expected, actual); + + expected = "Clef avec param"; + actual = I18n._("key.with.param", "param"); + Assert.assertEquals(expected, actual); + + // passage en anglais + + I18n.getStore().setLanguage(Locale.UK); + + expected = "Key with %s"; + actual = I18n._("key.with.param"); + Assert.assertEquals(expected, actual); + + expected = "Key with param"; + actual = I18n._("key.with.param", "param"); + Assert.assertEquals(expected, actual); + + // passage langue inconnue + + I18n.getStore().setLanguage(Locale.CHINA); + + expected = "key.with.param"; + actual = I18n._("key.with.param"); + Assert.assertEquals(expected, actual); + + expected = "key.with.param"; + actual = I18n._("key.with.param", "param"); + Assert.assertEquals(expected, actual); + } + + @Test + public void testMultiLanguage() { + + String expected; + String actual; + + // en français + + expected = "Clef avec %s"; + actual = I18n.l_(Locale.FRANCE, "key.with.param"); + Assert.assertEquals(expected, actual); + + expected = "Clef avec param"; + actual = I18n.l_(Locale.FRANCE, "key.with.param", "param"); + Assert.assertEquals(expected, actual); + + // en anglais + + I18n.getStore().setLanguage(Locale.UK); + + expected = "Key with %s"; + actual = I18n.l_(Locale.UK, "key.with.param"); + Assert.assertEquals(expected, actual); + + expected = "Key with param"; + actual = I18n.l_(Locale.UK, "key.with.param", "param"); + Assert.assertEquals(expected, actual); + + // dans une langue inconnue + + expected = "key.with.param"; + actual = I18n.l_(Locale.CHINA, "key.with.param"); + Assert.assertEquals(expected, actual); + + expected = "key.with.param"; + actual = I18n.l_(Locale.CHINA, "key.with.param", "param"); + Assert.assertEquals(expected, actual); + } +} Property changes on: trunk/nuiton-i18n/src/test/java/org/nuiton/i18n/I18nTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/nuiton-i18n/src/test/java/org/nuiton/util/LocaleConverterTest.java =================================================================== --- trunk/nuiton-i18n/src/test/java/org/nuiton/util/LocaleConverterTest.java 2011-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/test/java/org/nuiton/util/LocaleConverterTest.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -1,137 +0,0 @@ -/* - * #%L - * I18n :: Api - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2010 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.util; - -import junit.framework.TestCase; -import org.apache.commons.beanutils.Converter; - -import java.util.Locale; - -/** - * Tests {@link LocaleConverter}. - * - * @author tchemit <chemit@codelutin.com> - */ -public class LocaleConverterTest extends TestCase { - - String toConvert; - - Locale excepted; - - Converter converter; - - @Override - protected void setUp() throws Exception { - super.setUp(); - converter = new LocaleConverter(); - } - - public void testConvertFull() throws Exception { - toConvert = "fr_FR"; - excepted = Locale.FRANCE; - assertEquals(toConvert, excepted); - - toConvert = "fr_fr"; - assertEquals(toConvert, excepted); - - toConvert = "FR_fr"; - assertEquals(toConvert, excepted); - - toConvert = "FR_FR"; - assertEquals(toConvert, excepted); - - toConvert = "\n\tFr_fR "; - assertEquals(toConvert, excepted); - - toConvert = "en_GB"; - excepted = Locale.UK; - assertEquals(toConvert, excepted); - - toConvert = "en_US"; - excepted = Locale.US; - assertEquals(toConvert, excepted); - - //TODO Arch, we must also check coherence ! - toConvert = "fr_GB"; - excepted = new Locale("fr", "GB"); - assertEquals(toConvert, excepted); - } - - public void testConvertMedium() throws Exception { - toConvert = "fr"; - excepted = new Locale("fr"); - assertEquals(toConvert, excepted); - - toConvert = "fR"; - assertEquals(toConvert, excepted); - - toConvert = "FR"; - assertEquals(toConvert, excepted); - - toConvert = " fR \t"; - assertEquals(toConvert, excepted); - - toConvert = "en"; - excepted = new Locale("en"); - assertEquals(toConvert, excepted); - - toConvert = "es"; - excepted = new Locale("es"); - assertEquals(toConvert, excepted); - - } - - public void testConvertFailed() throws Exception { - - toConvert = null; - assertConvertFailed(toConvert); - - toConvert = ""; - assertConvertFailed(toConvert); - - toConvert = "fr_"; - assertConvertFailed(toConvert); - - toConvert = "_FR"; - assertConvertFailed(toConvert); - - } - - protected void assertEquals(String toConvert, Locale expected) { - Object result = converter.convert(Locale.class, toConvert); - assertEquals(expected, result); - } - - protected void assertConvertFailed(String toConvert) { - try { - converter.convert(Locale.class, toConvert); - fail(); - } catch (Exception e) { - assertTrue(true); - } - - } -} Copied: trunk/nuiton-i18n/src/test/java/org/nuiton/util/converter/LocaleConverterTest.java (from rev 1842, trunk/nuiton-i18n/src/test/java/org/nuiton/util/LocaleConverterTest.java) =================================================================== --- trunk/nuiton-i18n/src/test/java/org/nuiton/util/converter/LocaleConverterTest.java (rev 0) +++ trunk/nuiton-i18n/src/test/java/org/nuiton/util/converter/LocaleConverterTest.java 2011-01-19 21:38:53 UTC (rev 1844) @@ -0,0 +1,137 @@ +/* + * #%L + * I18n :: Api + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2010 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.util.converter; + +import junit.framework.TestCase; +import org.apache.commons.beanutils.Converter; + +import java.util.Locale; + +/** + * Tests {@link LocaleConverter}. + * + * @author tchemit <chemit@codelutin.com> + */ +public class LocaleConverterTest extends TestCase { + + String toConvert; + + Locale excepted; + + Converter converter; + + @Override + protected void setUp() throws Exception { + super.setUp(); + converter = new LocaleConverter(); + } + + public void testConvertFull() throws Exception { + toConvert = "fr_FR"; + excepted = Locale.FRANCE; + assertEquals(toConvert, excepted); + + toConvert = "fr_fr"; + assertEquals(toConvert, excepted); + + toConvert = "FR_fr"; + assertEquals(toConvert, excepted); + + toConvert = "FR_FR"; + assertEquals(toConvert, excepted); + + toConvert = "\n\tFr_fR "; + assertEquals(toConvert, excepted); + + toConvert = "en_GB"; + excepted = Locale.UK; + assertEquals(toConvert, excepted); + + toConvert = "en_US"; + excepted = Locale.US; + assertEquals(toConvert, excepted); + + //TODO Arch, we must also check coherence ! + toConvert = "fr_GB"; + excepted = new Locale("fr", "GB"); + assertEquals(toConvert, excepted); + } + + public void testConvertMedium() throws Exception { + toConvert = "fr"; + excepted = new Locale("fr"); + assertEquals(toConvert, excepted); + + toConvert = "fR"; + assertEquals(toConvert, excepted); + + toConvert = "FR"; + assertEquals(toConvert, excepted); + + toConvert = " fR \t"; + assertEquals(toConvert, excepted); + + toConvert = "en"; + excepted = new Locale("en"); + assertEquals(toConvert, excepted); + + toConvert = "es"; + excepted = new Locale("es"); + assertEquals(toConvert, excepted); + + } + + public void testConvertFailed() throws Exception { + + toConvert = null; + assertConvertFailed(toConvert); + + toConvert = ""; + assertConvertFailed(toConvert); + + toConvert = "fr_"; + assertConvertFailed(toConvert); + + toConvert = "_FR"; + assertConvertFailed(toConvert); + + } + + protected void assertEquals(String toConvert, Locale expected) { + Object result = converter.convert(Locale.class, toConvert); + assertEquals(expected, result); + } + + protected void assertConvertFailed(String toConvert) { + try { + converter.convert(Locale.class, toConvert); + fail(); + } catch (Exception e) { + assertTrue(true); + } + + } +} Property changes on: trunk/nuiton-i18n/src/test/java/org/nuiton/util/converter/LocaleConverterTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_en_GB.properties =================================================================== --- trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_en_GB.properties 2011-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_en_GB.properties 2011-01-19 21:38:53 UTC (rev 1844) @@ -24,3 +24,4 @@ ### key.one=First key.two=Second +key.with.param=Key with %s \ No newline at end of file Modified: trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_fr_FR.properties =================================================================== --- trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_fr_FR.properties 2011-01-19 20:29:56 UTC (rev 1843) +++ trunk/nuiton-i18n/src/test/resources/META-INF/I18nStoreTest_fr_FR.properties 2011-01-19 21:38:53 UTC (rev 1844) @@ -24,3 +24,4 @@ ### key.one=Premier key.two=Seconde +key.with.param=Clef avec %s
participants (1)
-
tchemit@users.nuiton.org