Class LocaleUtils
- Object
-
- LocaleUtils
-
public class LocaleUtils extends Object
Provides localized text strings to GUI elements. This class hides most of the fiddly bits associated with Locale and ResourceBundle from other gt-swing classes. You do not create instances of this class, it is basically just a wrapper around static data. Text strings are stored in properties files as per standard Java internationalization. All files are located in theorg/geotools/swing/locale
directory of the swing module.An application wishing to display GUI elements in a non-default locale must call either setLocale(Locale) or setLocale(List) before constructing any GUI elements which display localized text. At present, this class does not support switching locales for components that have already been constructed.
Clients retrieve text strings by specifying the base name of the relevant properties file and a key as shown here:
Adding support for a new language simply involves adding the new locale to all or some of the properties files. If the locale is only provided for some files, it will be recorded by as partially supported and used where available.String localizedText = LocaleUtils.getValue("CursorTool", "ZoomInTool");
You can set a single working locale with setLocale(Locale). If the specified locale is only partially supported, the getValue(String, String) method will fall back to the default Locale.ROOT when retrieving text strings lacking this locale. Alternatively, you can specify a list of locales in order of preference using the setLocale(List) method.
If the
setLocale
method is not called, the locale defaults to Locale.ROOT (which is English language in the properties files distributed with GeoTools).- Since:
- 8.0
- Author:
- Michael Bedward
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getValue(String baseFileName, String key)
Retrieves a GUI text string identified by the base name of a properties file and a key within that file.static boolean
isFullySupportedLocale(Locale locale)
Tests whether the givenLocale
is fully supported (ie. has been provided for every GUI text string properties file.static boolean
isSupportedLocale(Locale locale)
Tests whether the givenLocale
is supported.static void
setLocale(List<Locale> preferredLocales)
Sets the preferred locales for text string retrieval.static void
setLocale(Locale preferredLocale)
Sets a single preferred locale for text string retrieval.
-
-
-
Method Detail
-
isFullySupportedLocale
public static boolean isFullySupportedLocale(Locale locale)
Tests whether the givenLocale
is fully supported (ie. has been provided for every GUI text string properties file.- Parameters:
locale
- the locale- Returns:
true
if fully supported;false
if partially or not supported
-
isSupportedLocale
public static boolean isSupportedLocale(Locale locale)
Tests whether the givenLocale
is supported. A locale is treated as supported if it has been provided for at least one GUI text string properties file.- Parameters:
locale
- the locale- Returns:
true
if the locale is at least partially supported- See Also:
isFullySupportedLocale(Locale)
-
setLocale
public static void setLocale(Locale preferredLocale)
Sets a single preferred locale for text string retrieval. Any text strings for which this locale has not been provided will fall back to the default Locale.ROOT (English language). IfpreferredLocale
isnull
the working locale will be set to Locale.ROOT.- Parameters:
preferredLocale
- the locale
-
setLocale
public static void setLocale(List<Locale> preferredLocales)
Sets the preferred locales for text string retrieval. The input list is ordered from highest (first element) to lowest (last element) preference. There is no need to include Locale.ROOT in the input list. It will be added automatically. IfpreferredLocales
isnull
or empty, the working locale will be set to Locale.ROOT.- Parameters:
preferredLocales
- locales in descending order of preference
-
getValue
public static String getValue(String baseFileName, String key)
Retrieves a GUI text string identified by the base name of a properties file and a key within that file.String localName = LocaleUtils.getValue("CursorTool", "ZoomIn");
- Parameters:
baseFileName
- base name of the properties file containing the text stringkey
- key for the text string- Returns:
- the localized text string
- Throws:
MissingResourceException
- if thebaseFileName:key
pair cannot be foundIllegalArgumentException
- if either argument isnull
-
-