public class LocaleUtils extends Object
org/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:
String localizedText = LocaleUtils.getValue("CursorTool", "ZoomInTool");
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.
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).
Modifier and Type | Method and 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 given
Locale is fully supported (ie. has been provided for every
GUI text string properties file. |
static boolean |
isSupportedLocale(Locale locale)
Tests whether the given
Locale 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.
|
public static boolean isFullySupportedLocale(Locale locale)
Locale
is fully supported (ie. has been provided for every
GUI text string properties file.locale
- the localetrue
if fully supported; false
if partially or not supportedpublic static boolean isSupportedLocale(Locale locale)
Locale
is supported. A locale is treated as supported if it
has been provided for at least one GUI text string properties file.locale
- the localetrue
if the locale is at least partially supportedisFullySupportedLocale(Locale)
public static void setLocale(Locale preferredLocale)
preferredLocale
is null
the working locale will be set to
Locale.ROOT.preferredLocale
- the localepublic static void setLocale(List<Locale> preferredLocales)
preferredLocales
is null
or empty, the working locale will be set to Locale.ROOT.preferredLocales
- locales in descending order of preferencepublic static String getValue(String baseFileName, String key)
String localName = LocaleUtils.getValue("CursorTool", "ZoomIn");
baseFileName
- base name of the properties file containing the text stringkey
- key for the text stringMissingResourceException
- if the baseFileName:key
pair cannot be foundIllegalArgumentException
- if either argument is null
Copyright © 1996–2023 Geotools. All rights reserved.