Class Localizer
- All Implemented Interfaces:
ILocalizer
Easy to use and fully automatic setup and updating of locales.
Requires to have at least one default locale and one fallback locale in the resources. Use the create(Plugin, String...)
constructor for initial setup. This will create missing files
and updates existing files.
You can change the currently used locale every time via setLocale(String)
.
The localizer also allows to use locales which are not included in the resources folder.
- Since:
- 1.0.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.eldoria.eldoutilities.localization.ILocalizer
ILocalizer.DummyLocalizer
-
Field Summary
Fields inherited from interface de.eldoria.eldoutilities.localization.ILocalizer
DEFAULT, LOCALIZATION_CODE, LOCALIZER
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLocaleCodes
(Map<String, String> runtimeLocaleCodes) Add requested locale codes in runtime.static LocalizerBuilder
static ILocalizer
Deprecated, for removal: This API element is subject to removal in a future version.static ILocalizer
create
(Plugin plugin, String localesPath, String localesPrefix, Locale fallbackLocale, String... includedLocales) Deprecated, for removal: This API element is subject to removal in a future version.Use the builder provided bybuilder(Plugin, String)
String[]
Deprecated, for removal: This API element is subject to removal in a future version.getMessage
(String key) Get a message.getMessage
(String key, @Nullable CommandSender sender) getMessage
(String key, String language) getValue
(String key, CommandSender sender) Returns all available locales.localeBundle
(String language) Translates a String with Placeholders.localize
(CommandSender sender, String message) Translates a String with Placeholders.plugin()
void
registerChild
(ILocalizer localizer) void
setDefaultLocale
(String language) void
Deprecated, for removal: This API element is subject to removal in a future version.Use
-
Method Details
-
create
@Deprecated(forRemoval=true) public static ILocalizer create(Plugin plugin, String... includedLocales) Deprecated, for removal: This API element is subject to removal in a future version.Use the builder provided bybuilder(Plugin, String)
Create a new localizer instance with default values.The message path and prefix will be "messages" and the fallback language the "en_US" locale.
This instance will create locale files, which are provided in the "resources" directory.
After this it will update all locale files inside the locales directory. For this the ref keys from the internal default locale file will be used.
After a update check and an update if needed it will load the provided language or the fallback language if the provided language does not exist.
- Parameters:
plugin
- instance of pluginincludedLocales
- internal provided locales- Returns:
- the created localizer instance
-
create
@Deprecated(forRemoval=true) public static ILocalizer create(Plugin plugin, String localesPath, String localesPrefix, Locale fallbackLocale, String... includedLocales) Deprecated, for removal: This API element is subject to removal in a future version.Use the builder provided bybuilder(Plugin, String)
Create a new localizer instance.This instance will create locale files, which are provided in the "resources" directory.
After this it will update all locale files inside the locales directory. For this the ref keys from the internal default locale file will be used.
After a update check and an update if needed it will load the provided language or the fallback language if the provided language does not exist.
- Parameters:
plugin
- instance of pluginlocalesPath
- path of the locales directorylocalesPrefix
- prefix of the locale filesfallbackLocale
- fallbackLocaleincludedLocales
- internal provided locales- Returns:
- the created localizer instance
-
builder
-
plugin
- Specified by:
plugin
in interfaceILocalizer
-
setLocale
Deprecated, for removal: This API element is subject to removal in a future version.UseChange the locale to the language. If the locale is not present the fallback locale will be used.- Specified by:
setLocale
in interfaceILocalizer
- Parameters:
language
- language to be used
-
getMessage
Description copied from interface:ILocalizer
Get a message.- Specified by:
getMessage
in interfaceILocalizer
- Parameters:
key
- message key- Returns:
- message with replaced replacements if present.
-
setDefaultLocale
-
getMessage
- Specified by:
getMessage
in interfaceILocalizer
-
getValue
- Specified by:
getValue
in interfaceILocalizer
-
getMessage
- Specified by:
getMessage
in interfaceILocalizer
-
getValue
- Specified by:
getValue
in interfaceILocalizer
-
getValue
- Specified by:
getValue
in interfaceILocalizer
-
localeBundle
- Specified by:
localeBundle
in interfaceILocalizer
-
defaultBundle
- Specified by:
defaultBundle
in interfaceILocalizer
-
localize
Translates a String with Placeholders. Can handle multiple messages with replacements.- Specified by:
localize
in interfaceILocalizer
- Parameters:
message
- Message to translate- Returns:
- Replaced Messages
-
localize
Description copied from interface:ILocalizer
Translates a String with Placeholders. Can handle multiple messages with replacements. Add replacements in the right order.- Specified by:
localize
in interfaceILocalizer
message
- Message to translate- Returns:
- Replaced Messages
-
getIncludedLocales
Deprecated, for removal: This API element is subject to removal in a future version.Get currently registered locales.- Specified by:
getIncludedLocales
in interfaceILocalizer
- Returns:
- array of available locales.
-
includedLocales
Description copied from interface:ILocalizer
Returns all available locales.- Specified by:
includedLocales
in interfaceILocalizer
- Returns:
- set of registered locales.
-
addLocaleCodes
Description copied from interface:ILocalizer
Add requested locale codes in runtime.This has to be done before calling
ILocalizer.setLocale(String)
Every key has one default value which will be added to the file if the key is not present.
- Specified by:
addLocaleCodes
in interfaceILocalizer
- Parameters:
runtimeLocaleCodes
- map with locales codes to add.
-
registerChild
- Specified by:
registerChild
in interfaceILocalizer
-
builder(Plugin, String)