Index: lutinutil/src/java/org/codelutin/i18n/LocaleEnum.java diff -u /dev/null lutinutil/src/java/org/codelutin/i18n/LocaleEnum.java:1.1 --- /dev/null Thu Feb 21 22:29:50 2008 +++ lutinutil/src/java/org/codelutin/i18n/LocaleEnum.java Thu Feb 21 22:29:45 2008 @@ -0,0 +1,83 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* 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 Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package org.codelutin.i18n; + +import static org.codelutin.i18n.I18n._; +import static org.codelutin.i18n.I18n.n_; + +import java.util.Locale; + +/** + * Une énumération pour représenter des locales utilisateurs. + * + * TODO add other locales + * + * @author chemit + */ +public enum LocaleEnum { + + fr(LanguageEnum.fr, CountryEnum.FR, n_("lutinutil.i18n.locale.fr")), + gb(LanguageEnum.en, CountryEnum.GB, n_("lutinutil.i18n.locale.en")); + + private CountryEnum country; + private LanguageEnum langage; + private String libelle; + private Locale locale; + + LocaleEnum(LanguageEnum language, CountryEnum country, String libelle) { + this.langage = language; + this.country = country; + this.libelle = libelle; + } + + public CountryEnum getCountry() { + return country; + } + + public LanguageEnum getLangage() { + return langage; + } + + public String getLibelle() { + return libelle; + } + + public String getBundle() { + return langage.name() + "_" + country.name(); + } + + public Locale getLocale() { + if (locale == null) { + locale = new Locale(langage.name(),country.name()); + } + return locale; + } + + public static LocaleEnum valueOf(String locale, LocaleEnum defaultValue) { + LocaleEnum localeValue = null; + try { + localeValue = LocaleEnum.valueOf(locale.toLowerCase()); + } catch (IllegalArgumentException e) { + System.err.println(_("lutinutil.error.i18n.unfound.locale", locale, defaultValue)); + } catch (NullPointerException e) { + System.err.println(_("lutinutil.error.i18n.unfound.locale", locale, defaultValue)); + } + return localeValue == null ? defaultValue : localeValue; + } +} \ No newline at end of file