public class I18n extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
I18n.RemovalReference
Identifying container for a removal reference.
|
static class |
I18n.Source
A localization (l10n) source.
|
| Modifier and Type | Field and Description |
|---|---|
static boolean |
LOG_UNKNOWN_KEYS
Whether to log access to unknown keys.
|
| Constructor and Description |
|---|
I18n(I18n.Source source)
Creates a new i18n handler.
|
I18n(I18n.Source source,
Locale currentLocale)
Creates a new i18n handler.
|
I18n(String name,
String propertiesPath,
Locale defaultLocale)
Creates a new i18n handler.
|
I18n(String name,
String propertiesPath,
Locale defaultLocale,
ClassLoader classLoader,
Locale currentLocale)
Creates a new i18n handler.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addI18nable(I18nable i18nable)
Adds an i18n listener that is notified when the language is changed or
additional sources add added or removed.
|
void |
addI18nable(I18nable i18nable,
I18n.RemovalReference removalReference)
Adds an i18n listener that is notified when the language is changed or
additional sources add added or removed.
|
void |
addSource(I18n.Source source)
Adds an additional l10n source.
|
String |
get(String key,
Object... parameters)
Returns the translated value for the given key.
|
int |
getKey(String key)
Returns the keycode from the value of the given key.
|
KeyStroke |
getKeyStroke(String key)
Returns a key stroke for use with swing accelerators.
|
Locale |
getLocale()
Returns the current locale.
|
boolean |
has(String key)
Returns whether the current translation contains the given key.
|
void |
removeI18nable(I18nable i18nable)
Removes an i18n listener.
|
void |
removeI18nables(I18n.RemovalReference removalReference)
Removes all i18n listeners that have been
addI18nable(I18nable, RemovalReference) using the given object
as removal reference. |
void |
removeSource(I18n.Source source)
Removes an additional l10n source.
|
void |
setLocale(Locale locale)
Sets the current locale.
|
void |
useMessageFormat(boolean useMessageFormat)
Sets whether to use
MessageFormat for formatting values with
parameters. |
public static boolean LOG_UNKNOWN_KEYS
public I18n(String name, String propertiesPath, Locale defaultLocale)
name - The name of the applicationpropertiesPath - The path of the propertiesdefaultLocale - The default locale of the applicationpublic I18n(String name, String propertiesPath, Locale defaultLocale, ClassLoader classLoader, Locale currentLocale)
name - The name of the applicationpropertiesPath - The path of the propertiesdefaultLocale - The default locale of the applicationclassLoader - The class loader used to load the propertiescurrentLocale - The current localepublic I18n(I18n.Source source)
source - The l10n sourcepublic I18n(I18n.Source source, Locale currentLocale)
source - The l10n sourcecurrentLocale - The current localepublic void addI18nable(I18nable i18nable)
i18nable - The i18n listener to addpublic void addI18nable(I18nable i18nable, I18n.RemovalReference removalReference)
i18nable - The i18n listener to addremovalReference - Removal reference (optional)public void removeI18nable(I18nable i18nable)
i18nable - The i18n listener to removepublic void removeI18nables(I18n.RemovalReference removalReference)
addI18nable(I18nable, RemovalReference) using the given object
as removal reference.removalReference - The removal referencepublic void useMessageFormat(boolean useMessageFormat)
MessageFormat for formatting values with
parameters.useMessageFormat - true to use MessageFormat, false to
use String.format(String, Object...)public Locale getLocale()
public void setLocale(Locale locale)
locale - The new localepublic void addSource(I18n.Source source)
source - The l10n source to addpublic void removeSource(I18n.Source source)
source - The l10n source to removepublic boolean has(String key)
key - The key to check fortrue if there is a translation for the given key, false otherwisepublic String get(String key, Object... parameters)
key - The key to get the translation forparameters - Parameters to substitute in the value of the keyFormatterpublic int getKey(String key)
KeyEvent in the properties file, e.g. VK_S for the
keycode ‘s’ when used for mnemonics.key - The key under which the keycode is storedCopyright © 2026. All rights reserved.