summaryrefslogtreecommitdiff
path: root/gnu/java/locale/LocaleHelper.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-31 01:37:09 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-31 01:37:09 +0000
commit6b198c81e06cfb3bfa3133ec57876809325128c4 (patch)
tree33f131fa1ff0e537feed3460e5fe3bfc0ea4c2b4 /gnu/java/locale/LocaleHelper.java
parent72313cc4ac03a612709abf1a7bba40d431594632 (diff)
downloadclasspath-6b198c81e06cfb3bfa3133ec57876809325128c4.tar.gz
2005-01-31 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/java/locale/LocaleHelper.java: New utility class. (getLocalizedString(java.util.Locale, String, String, boolean, boolean)): More generic version of what was java.util.Locale.getDisplayString, now available to all classes. * gnu/java/locale/LocaleInformation.java, gnu/java/locale/LocaleInformation_aa.java, gnu/java/locale/LocaleInformation_aa_ET.java, gnu/java/locale/LocaleInformation_af.java, gnu/java/locale/LocaleInformation_am.java, gnu/java/locale/LocaleInformation_am_ET.java, gnu/java/locale/LocaleInformation_ar.java, gnu/java/locale/LocaleInformation_as.java, gnu/java/locale/LocaleInformation_az.java, gnu/java/locale/LocaleInformation_be.java, gnu/java/locale/LocaleInformation_bg.java, gnu/java/locale/LocaleInformation_bn.java, gnu/java/locale/LocaleInformation_byn.java gnu/java/locale/LocaleInformation_byn_ER.java gnu/java/locale/LocaleInformation_ca.java, gnu/java/locale/LocaleInformation_cs.java, gnu/java/locale/LocaleInformation_cy.java, gnu/java/locale/LocaleInformation_da.java, gnu/java/locale/LocaleInformation_de.java, gnu/java/locale/LocaleInformation_de_AT.java, gnu/java/locale/LocaleInformation_de_BE.java, gnu/java/locale/LocaleInformation_de_CH.java, gnu/java/locale/LocaleInformation_de_LU.java, gnu/java/locale/LocaleInformation_dv.java, gnu/java/locale/LocaleInformation_dz.java, gnu/java/locale/LocaleInformation_dz_BT.java, gnu/java/locale/LocaleInformation_el.java, gnu/java/locale/LocaleInformation_el_GR.java, gnu/java/locale/LocaleInformation_en.java, gnu/java/locale/LocaleInformation_en_AU.java, gnu/java/locale/LocaleInformation_en_BE.java, gnu/java/locale/LocaleInformation_en_CA.java, gnu/java/locale/LocaleInformation_en_GB.java, gnu/java/locale/LocaleInformation_en_HK.java, gnu/java/locale/LocaleInformation_en_IE.java, gnu/java/locale/LocaleInformation_en_MT.java, gnu/java/locale/LocaleInformation_en_NZ.java, gnu/java/locale/LocaleInformation_en_PH.java, gnu/java/locale/LocaleInformation_en_SG.java, gnu/java/locale/LocaleInformation_en_US.java, gnu/java/locale/LocaleInformation_en_ZW.java, gnu/java/locale/LocaleInformation_eo.java, gnu/java/locale/LocaleInformation_es.java, gnu/java/locale/LocaleInformation_es_AR.java, gnu/java/locale/LocaleInformation_es_CL.java, gnu/java/locale/LocaleInformation_es_CO.java, gnu/java/locale/LocaleInformation_es_ES.java, gnu/java/locale/LocaleInformation_es_MX.java, gnu/java/locale/LocaleInformation_es_PR.java, gnu/java/locale/LocaleInformation_et.java, gnu/java/locale/LocaleInformation_eu.java, gnu/java/locale/LocaleInformation_fa.java, gnu/java/locale/LocaleInformation_fa_AF.java, gnu/java/locale/LocaleInformation_fi.java, gnu/java/locale/LocaleInformation_fo.java, gnu/java/locale/LocaleInformation_fr.java, gnu/java/locale/LocaleInformation_fr_CA.java, gnu/java/locale/LocaleInformation_fr_LU.java, gnu/java/locale/LocaleInformation_ga.java, gnu/java/locale/LocaleInformation_ga_IE.java, gnu/java/locale/LocaleInformation_gez.java gnu/java/locale/LocaleInformation_gez_ER.java gnu/java/locale/LocaleInformation_gez_ET.java gnu/java/locale/LocaleInformation_gl.java, gnu/java/locale/LocaleInformation_gu.java, gnu/java/locale/LocaleInformation_gv.java, gnu/java/locale/LocaleInformation_haw.java gnu/java/locale/LocaleInformation_haw_US.java gnu/java/locale/LocaleInformation_he.java, gnu/java/locale/LocaleInformation_hi.java, gnu/java/locale/LocaleInformation_hr.java, gnu/java/locale/LocaleInformation_hu.java, gnu/java/locale/LocaleInformation_hy.java, gnu/java/locale/LocaleInformation_id.java, gnu/java/locale/LocaleInformation_is.java, gnu/java/locale/LocaleInformation_it.java, gnu/java/locale/LocaleInformation_it_IT.java, gnu/java/locale/LocaleInformation_iu.java, gnu/java/locale/LocaleInformation_ja.java, gnu/java/locale/LocaleInformation_ka.java, gnu/java/locale/LocaleInformation_kk.java, gnu/java/locale/LocaleInformation_kl.java, gnu/java/locale/LocaleInformation_km.java, gnu/java/locale/LocaleInformation_kn.java, gnu/java/locale/LocaleInformation_ko.java, gnu/java/locale/LocaleInformation_kok.java gnu/java/locale/LocaleInformation_kok_IN.java gnu/java/locale/LocaleInformation_kw.java, gnu/java/locale/LocaleInformation_ky.java, gnu/java/locale/LocaleInformation_lo.java, gnu/java/locale/LocaleInformation_lt.java, gnu/java/locale/LocaleInformation_lv.java, gnu/java/locale/LocaleInformation_mk.java, gnu/java/locale/LocaleInformation_ml.java, gnu/java/locale/LocaleInformation_mn.java, gnu/java/locale/LocaleInformation_mn_MN.java, gnu/java/locale/LocaleInformation_mr.java, gnu/java/locale/LocaleInformation_ms.java, gnu/java/locale/LocaleInformation_ms_BN.java, gnu/java/locale/LocaleInformation_mt.java, gnu/java/locale/LocaleInformation_nb.java, gnu/java/locale/LocaleInformation_nl.java, gnu/java/locale/LocaleInformation_nn.java, gnu/java/locale/LocaleInformation_om.java, gnu/java/locale/LocaleInformation_om_ET.java, gnu/java/locale/LocaleInformation_or.java, gnu/java/locale/LocaleInformation_pa.java, gnu/java/locale/LocaleInformation_pl.java, gnu/java/locale/LocaleInformation_ps.java, gnu/java/locale/LocaleInformation_pt.java, gnu/java/locale/LocaleInformation_pt_PT.java, gnu/java/locale/LocaleInformation_ro.java, gnu/java/locale/LocaleInformation_ru.java, gnu/java/locale/LocaleInformation_sa.java, gnu/java/locale/LocaleInformation_sid.java gnu/java/locale/LocaleInformation_sid_ET.java gnu/java/locale/LocaleInformation_sk.java, gnu/java/locale/LocaleInformation_sl.java, gnu/java/locale/LocaleInformation_so.java, gnu/java/locale/LocaleInformation_so_DJ.java, gnu/java/locale/LocaleInformation_so_ET.java, gnu/java/locale/LocaleInformation_so_SO.java, gnu/java/locale/LocaleInformation_sq.java, gnu/java/locale/LocaleInformation_sr.java, gnu/java/locale/LocaleInformation_sr_Latn.java, gnu/java/locale/LocaleInformation_sv.java, gnu/java/locale/LocaleInformation_sw.java, gnu/java/locale/LocaleInformation_syr.java gnu/java/locale/LocaleInformation_syr_SY.java gnu/java/locale/LocaleInformation_ta.java, gnu/java/locale/LocaleInformation_te.java, gnu/java/locale/LocaleInformation_th.java, gnu/java/locale/LocaleInformation_ti.java, gnu/java/locale/LocaleInformation_ti_ER.java, gnu/java/locale/LocaleInformation_ti_ET.java, gnu/java/locale/LocaleInformation_tig.java gnu/java/locale/LocaleInformation_tig_ER.java gnu/java/locale/LocaleInformation_tr.java, gnu/java/locale/LocaleInformation_tt.java, gnu/java/locale/LocaleInformation_uk.java, gnu/java/locale/LocaleInformation_ur.java, gnu/java/locale/LocaleInformation_uz.java, gnu/java/locale/LocaleInformation_uz_AF.java, gnu/java/locale/LocaleInformation_vi.java, gnu/java/locale/LocaleInformation_wal.java gnu/java/locale/LocaleInformation_wal_ET.java gnu/java/locale/LocaleInformation_zh.java, gnu/java/locale/LocaleInformation_zh_HK_Hant.java, gnu/java/locale/LocaleInformation_zh_Hant.java, gnu/java/locale/LocaleInformation_zh_MO_Hant.java, gnu/java/locale/LocaleInformation_zh_SG_Hans.java, Locales updated with re-ordered zone strings, new separator ('|' replaced with \u00A6) and updated data from the latest CLDR CVS (including 16 new locales). * java/util/Currency.java: (currencySymbol): Removed. (getCurrencyCode()): Rewritten to call getCurrencyCode(Locale.getDefault()). (getCurrencyCode(java.util.Locale)): Rewritten to lookup localized currency symbol from our locale data. * java/util/Locale.java: (getDisplayLanguage(java.util.Locale)): Now calls method in LocaleHelper. (getDisplayCountry(java.util.Locale)): Likewise. (getDisplayVariant(java.util.Locale)): Likewise. (getDisplayString()): Rewritten in LocaleHelper.
Diffstat (limited to 'gnu/java/locale/LocaleHelper.java')
-rw-r--r--gnu/java/locale/LocaleHelper.java161
1 files changed, 161 insertions, 0 deletions
diff --git a/gnu/java/locale/LocaleHelper.java b/gnu/java/locale/LocaleHelper.java
new file mode 100644
index 000000000..036c868e9
--- /dev/null
+++ b/gnu/java/locale/LocaleHelper.java
@@ -0,0 +1,161 @@
+/* LocaleHelper.java -- helper routines for localization
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath 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, or (at your option)
+any later version.
+
+GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.locale;
+
+import java.util.Locale;
+import java.util.Hashtable;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * This class provides common helper methods
+ * for handling localized data.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @see java.util.Locale
+ * @see java.util.ResourceBundle
+ */
+public class LocaleHelper
+{
+
+ /**
+ * This method is used by the localized name lookup methods to retrieve
+ * the localized name of a particular piece of locale data.
+ * If the display name can not be localized to the supplied
+ * locale, it will fall back on other output in the following order:
+ * </p>
+ * <ul>
+ * <li>the localized name in the default locale</li>
+ * <li>the localized name in English (optional)</li>
+ * <li>the localized name in the root locale bundle (optional)</li>
+ * <li>the localized input string</li>
+ * </ul>
+ * <p>
+ * If the supplied key is merely the empty string, then the empty string is
+ * returned.
+ * </p>
+ *
+ * @param inLocale the locale to use for formatting the display string.
+ * @param key the locale data used as a key to the localized lookup tables.
+ * @param name the name of the hashtable containing the localized data.
+ * @param checkEnglish true if the method should fall back on data
+ * from the English locale.
+ * @param checkRoot true if the method should fall back on data from the
+ * unlocalized root locale.
+ * @return a <code>String</code>, hopefully containing the localized
+ * variant of the input data.
+ * @throws NullPointerException if <code>inLocale</code> is null.
+ */
+ public static String getLocalizedString(Locale inLocale, String key,
+ String name, boolean checkEnglish,
+ boolean checkRoot)
+ {
+ String localizedString;
+ Hashtable table;
+
+ if (key.equals(""))
+ return "";
+ /* Localize to inLocale */
+ try
+ {
+ table = (Hashtable)
+ ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
+ inLocale).getObject(name);
+ localizedString = (String) table.get(key);
+ }
+ catch (MissingResourceException exception)
+ {
+ localizedString = null;
+ }
+ /* Localize to default locale */
+ if (localizedString == null)
+ {
+ try
+ {
+ ResourceBundle bundle;
+
+ bundle =
+ ResourceBundle.getBundle("gnu.java.locale.LocaleInformation");
+ table = (Hashtable) bundle.getObject(name);
+ localizedString = (String) table.get(key);
+ }
+ catch (MissingResourceException exception)
+ {
+ localizedString = null;
+ }
+ }
+ /* Localize to English */
+ if (localizedString == null && checkEnglish)
+ {
+ try
+ {
+ table = (Hashtable)
+ ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
+ Locale.ENGLISH).getObject(name);
+ localizedString= (String) table.get(key);
+ }
+ catch (MissingResourceException exception)
+ {
+ localizedString = null;
+ }
+ }
+ /* Return unlocalized version */
+ if (localizedString == null && checkRoot)
+ {
+ try
+ {
+ table = (Hashtable)
+ ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
+ new Locale("","","")).getObject(name);
+ localizedString= (String) table.get(key);
+ }
+ catch (MissingResourceException exception)
+ {
+ localizedString = null;
+ }
+ }
+ /* Return original input string */
+ if (localizedString == null)
+ {
+ localizedString = key;
+ }
+ return localizedString;
+ }
+}
+