Holger's
Java API

com.antelmann.util
Class I18n

java.lang.Object
  extended by com.antelmann.util.I18n

public final class I18n
extends Object

some utility methods useful for internationalization.

Author:
Holger Antelmann
See Also:
Country

Method Summary
static Locale findCountryMatch(Locale locale, Collection<Locale> candidates)
          tries to find a matching Locale within the given collection with respect to the country.
static Locale findLanguageMatch(Locale locale, Collection<Locale> candidates)
          tries to find a matching Locale within the given collection with respect to the language.
static String getCountryCodeForName(String countryName)
           
static String getCountryCodeForName(String countryName, Locale l)
          returns the corresponding 2-letter code if the country is found or null
static ImageIcon getCountryIcon(String countryCode)
          returns a 16 x 11 pixel icon for the given country code or null if no icon is available
static ResourceBundle getCountryLanguage()
           
static ResourceBundle getCountryLanguage(Locale l)
          maps the 2-letter country code to the display name
static String getCountryLanguageBundleName()
           
static String getCountryName(String countryCode)
           
static String getCountryName(String countryCode, Locale l)
          returns the display name of any ISO 3166 2-letter country code in the given language
static ArrayList<String> getCountryNames()
           
static ArrayList<String> getCountryNames(Locale l)
          returns all existing ISO country names that can be mapped to a code in a newly created and sorted list
static HashSet<Currency> getCurrencies()
           
static String getDefaultCountryName()
           
static String[] getEUCountryCodes()
           
static String[] getEUCountryCodes(boolean reRead)
          the return value can be altered by setting the property 'eu.countries' in the Settings to a comma/semicolon/space/tab separated list of country codes
static String getLanguageCodeForName(String name)
          returns the corresponding ISO 639 language code for the given name based on the default Locale
static String getLanguageCodeForName(String str, Locale l)
          returns the corresponding ISO 639 language code for the given name based on the given Locale
static JComboBox getLanguageComboBox(boolean useFullName)
           
static JComboBox getLanguageComboBox(boolean useFullName, Locale l)
          provides a component for selecting languages based on either ISO 639 code or the full name
static JComboBox getLanguageComboBox(String[] lang, Locale displayLang)
          provides a component for selecting languages based on the given array
static String[] getLanguageNames()
          returns an (unsorted) array of localized names for all ISO 639 languages based on the default Locale
static String[] getLanguageNames(Locale l)
          returns an (unsorted) array of localized names for all ISO 639 languages based on the given Locale
static FormattedCellRenderer getLanguageRenderer()
           
static FormattedCellRenderer getLanguageRenderer(Locale l)
           
static Object getLocalized(Map<?,?> properties, String keyBase, Locale locale)
          uses a default ResourceBundle.Control to fulfill the request
static Object getLocalized(Map<?,?> properties, String keyBase, Locale locale, ResourceBundle.Control control)
          searches the properties for a suitable localized key and returns its value.
static ArrayList<String> getSupportedCountryNames()
           
static ArrayList<String> getSupportedCountryNames(Locale language)
          returns a sorted list of all supported country names in the given language.
static boolean isEUCountry(String countryCode)
          returns true only if the given ISO 3166 country code belongs to a country within the European Union
static boolean isISOCountry(String countryCode)
          based on uppercase ISO 3166 2-letter code (comparison is case-insensitive, though)
static boolean isSupportedCountry(String countryCode)
          returns true only if there is a Locale available for that country code
static boolean isUseBundle()
           
static Locale localeFor(String localeIdentifier)
          retrieves the Locale based on the toString() method of a supported Locale, or null if none is available.
static Locale localeForCountry(String countryCode)
          retrieves an existing predefined Locale based on a given uppercase ISO 3166 2-letter code or null if none is available (note that not all supported countries have an associated Locale).
static Locale localeForCountryName(String countryName)
           
static Locale localeForCountryName(String countryName, Locale locale)
           
static String sampleString(Locale l)
          returns a sample String for the given locale - displayed in the default locale
static String sampleString(Locale locale, Locale language)
          returns a sample String for the given locale displayed in the given language
static void setCountryLanguageBundleName(String bundleName)
           
static void setUseBundle(boolean flag)
          if true, a custom resource bundle is used to determine country names
static Locale toLocale(String str)
          returns a Locale by parsing the given string assuming that the string is derived from the toString() method of some Locale.
static Properties toProperties(ResourceBundle bundle)
           
static ResourceBundle toResourceBundle(Map<?,?> data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCountryLanguageBundleName

public static String getCountryLanguageBundleName()

setCountryLanguageBundleName

public static void setCountryLanguageBundleName(String bundleName)

isUseBundle

public static boolean isUseBundle()

setUseBundle

public static void setUseBundle(boolean flag)
if true, a custom resource bundle is used to determine country names

See Also:
getCountryName(String, Locale), setCountryLanguageBundleName(String)

getLocalized

public static Object getLocalized(Map<?,?> properties,
                                  String keyBase,
                                  Locale locale)
uses a default ResourceBundle.Control to fulfill the request


getLocalized

public static Object getLocalized(Map<?,?> properties,
                                  String keyBase,
                                  Locale locale,
                                  ResourceBundle.Control control)
searches the properties for a suitable localized key and returns its value. E.g. if the properties contained a key named test_de mapping to some non-null value, that value would be returned before looking for a property key named test with a German locale, when test was given as a keyBase.


sampleString

public static String sampleString(Locale l)
returns a sample String for the given locale - displayed in the default locale


sampleString

public static String sampleString(Locale locale,
                                  Locale language)
returns a sample String for the given locale displayed in the given language


getCountryLanguage

public static ResourceBundle getCountryLanguage()

getCountryLanguage

public static ResourceBundle getCountryLanguage(Locale l)
maps the 2-letter country code to the display name


getCountryName

public static String getCountryName(String countryCode)
                             throws NullPointerException,
                                    MissingResourceException
Throws:
NullPointerException
MissingResourceException

getCountryName

public static String getCountryName(String countryCode,
                                    Locale l)
                             throws NullPointerException,
                                    MissingResourceException
returns the display name of any ISO 3166 2-letter country code in the given language

Throws:
NullPointerException
MissingResourceException

getCountryCodeForName

public static String getCountryCodeForName(String countryName)

getCountryCodeForName

public static String getCountryCodeForName(String countryName,
                                           Locale l)
returns the corresponding 2-letter code if the country is found or null


getDefaultCountryName

public static String getDefaultCountryName()

getCountryNames

public static ArrayList<String> getCountryNames()

getCountryNames

public static ArrayList<String> getCountryNames(Locale l)
returns all existing ISO country names that can be mapped to a code in a newly created and sorted list


toLocale

public static Locale toLocale(String str)
                       throws IllegalArgumentException
returns a Locale by parsing the given string assuming that the string is derived from the toString() method of some Locale.

Throws:
IllegalArgumentException

localeFor

public static Locale localeFor(String localeIdentifier)
retrieves the Locale based on the toString() method of a supported Locale, or null if none is available. The string comparison is case-sensitive.


localeForCountryName

public static Locale localeForCountryName(String countryName)

localeForCountryName

public static Locale localeForCountryName(String countryName,
                                          Locale locale)

getSupportedCountryNames

public static ArrayList<String> getSupportedCountryNames()
See Also:
getSupportedCountryNames(Locale)

getSupportedCountryNames

public static ArrayList<String> getSupportedCountryNames(Locale language)
returns a sorted list of all supported country names in the given language. A country is supported if there is an associated Locale available for it.


localeForCountry

public static Locale localeForCountry(String countryCode)
retrieves an existing predefined Locale based on a given uppercase ISO 3166 2-letter code or null if none is available (note that not all supported countries have an associated Locale). If there is more than one supported Locale object for the given country code, simply the first one encountered is returned.


isSupportedCountry

public static boolean isSupportedCountry(String countryCode)
returns true only if there is a Locale available for that country code


getEUCountryCodes

public static String[] getEUCountryCodes()

getEUCountryCodes

public static String[] getEUCountryCodes(boolean reRead)
the return value can be altered by setting the property 'eu.countries' in the Settings to a comma/semicolon/space/tab separated list of country codes

See Also:
Settings.setProperty(String, String)

isISOCountry

public static boolean isISOCountry(String countryCode)
based on uppercase ISO 3166 2-letter code (comparison is case-insensitive, though)


isEUCountry

public static boolean isEUCountry(String countryCode)
returns true only if the given ISO 3166 country code belongs to a country within the European Union


getCurrencies

public static HashSet<Currency> getCurrencies()

getLanguageComboBox

public static JComboBox getLanguageComboBox(boolean useFullName)
See Also:
getLanguageComboBox(boolean, Locale)

getLanguageComboBox

public static JComboBox getLanguageComboBox(boolean useFullName,
                                            Locale l)
provides a component for selecting languages based on either ISO 639 code or the full name

Parameters:
useFullName - if true, the full language name is used as a selectable value instead of the ISO 639 code
l - the language used for the display of the language
See Also:
getLanguageCodeForName(String, Locale)

getLanguageComboBox

public static JComboBox getLanguageComboBox(String[] lang,
                                            Locale displayLang)
provides a component for selecting languages based on the given array

Parameters:
lang - an array of either ISO 639 codes or language names based on the given Locale
displayLang - the language used for the display of the language
See Also:
getLanguageCodeForName(String, Locale)

getLanguageRenderer

public static FormattedCellRenderer getLanguageRenderer()

getLanguageRenderer

public static FormattedCellRenderer getLanguageRenderer(Locale l)

getLanguageNames

public static String[] getLanguageNames()
returns an (unsorted) array of localized names for all ISO 639 languages based on the default Locale


getLanguageNames

public static String[] getLanguageNames(Locale l)
returns an (unsorted) array of localized names for all ISO 639 languages based on the given Locale


getLanguageCodeForName

public static String getLanguageCodeForName(String name)
returns the corresponding ISO 639 language code for the given name based on the default Locale


getLanguageCodeForName

public static String getLanguageCodeForName(String str,
                                            Locale l)
returns the corresponding ISO 639 language code for the given name based on the given Locale


getCountryIcon

public static ImageIcon getCountryIcon(String countryCode)
returns a 16 x 11 pixel icon for the given country code or null if no icon is available


findLanguageMatch

public static Locale findLanguageMatch(Locale locale,
                                       Collection<Locale> candidates)
tries to find a matching Locale within the given collection with respect to the language. If a direct match is found, it will be returned. Next, this method looks for a language match (first with the given variant, then without). If no language match is found, null is returned.


findCountryMatch

public static Locale findCountryMatch(Locale locale,
                                      Collection<Locale> candidates)
tries to find a matching Locale within the given collection with respect to the country. If a direct match is found, it will be returned. Next, this method looks for the best country match (in regards to the language). If no language match is found, null is returned.


toResourceBundle

public static ResourceBundle toResourceBundle(Map<?,?> data)

toProperties

public static Properties toProperties(ResourceBundle bundle)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads