Class TranslationBundle
MessageFormat
notation.
The purpose of this class is similar to ResourceBundle
.
Older versions of this library used to contain a direct ResourceBundle
subclass, but ResourceBundle is very old and contains a lot of obscure
functionality. This class provides a similar API to ResourceBundle, and
supports loading text from properties
files. However, it is more
flexible and allows to load text from various other sources. It also allows
custom file names and locations, instead of the predefined naming convention
required by ResourceBundle
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic TranslationBundle
from
(Properties defaultTranslation) Returns aTranslationBundle
that will use the specifiedProperties
as its default translation.static TranslationBundle
from
(ResourceFile propertiesFile) Loads the specified.properties
file, then uses the resulting properties as the default translation for aTranslationBundle
.static TranslationBundle
Returns aTranslationBundle
that will use the key/value properties in the specified map as its default translation.static TranslationBundle
fromPropertiesFile
(String propertiesFileContents) Returns aTranslationBundle
that loads the contents of a.properties
file, then uses the resulting properties as the default translation.getKeys()
Returns all translation keys that exist for the default translation.Returns all translation keys that exist for the translation for the specified locale, using the default translation as a fallback where necessary.Provided for API compatibility withResourceBundle
and theDynamicResourceBundle
subclass that used to be included in previous versions of this library.Returns the text string with the specified key for the default translation.Returns the text string with the specified key, for the requested locale.withTranslation
(Locale locale, TranslationBundle translation) Returns a newTranslationBundle
that adds the specified translation.
-
Method Details
-
withTranslation
Returns a newTranslationBundle
that adds the specified translation. ThisTranslationBundle
's default translation will act as a fallback for any keys that are not included in the translation.- Throws:
IllegalArgumentException
- if thisTranslationBundle
already includes a translation for the same locale.
-
getText
Returns the text string with the specified key, for the requested locale. If no suitable translation exists, the default translation is used as a fallback. If the default translation is also not available, the key is returned as a last resort. -
getText
Returns the text string with the specified key for the default translation. If no translation is also available, the key is returned as a fallback. -
getString
Provided for API compatibility withResourceBundle
and theDynamicResourceBundle
subclass that used to be included in previous versions of this library. This method will redirect togetText(Locale, String, Object...)
and will use the default translation. -
getKeys
Returns all translation keys that exist for the translation for the specified locale, using the default translation as a fallback where necessary. The keys will be returned in random order. -
getKeys
Returns all translation keys that exist for the default translation. The keys will be returned in random order. -
from
Returns aTranslationBundle
that will use the specifiedProperties
as its default translation. Additional translations can be added afterward. -
from
Loads the specified.properties
file, then uses the resulting properties as the default translation for aTranslationBundle
. Additional translations can be added afterward.PropertyUtils.loadProperties(ResourceFile)
is used to load the file. Refer to the documentation of that method for more information on supported character encodings for different platforms. -
fromPropertiesFile
Returns aTranslationBundle
that loads the contents of a.properties
file, then uses the resulting properties as the default translation. Additional translations can be added afterward.PropertyUtils.loadProperties(String)
is used to load the file. Refer to the documentation of that method for more information on supported character encodings for different platforms. -
fromMap
Returns aTranslationBundle
that will use the key/value properties in the specified map as its default translation. Additional translations can be added afterward.
-