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 TypeMethodDescriptionvoidaddLocaleCodes(Map<String, String> runtimeLocaleCodes) Add requested locale codes in runtime.static LocalizerBuilderstatic ILocalizerDeprecated, for removal: This API element is subject to removal in a future version.static ILocalizercreate(org.bukkit.plugin.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 org.bukkit.command.CommandSender sender) getMessage(String key, String language) Returns all available locales.localeBundle(String language) Translates a String with Placeholders.Translates a String with Placeholders.org.bukkit.plugin.Pluginplugin()voidregisterChild(ILocalizer localizer) voidsetDefaultLocale(String language) voidDeprecated, for removal: This API element is subject to removal in a future version.Use
-
Method Details
-
create
@Deprecated(forRemoval=true) public static ILocalizer create(org.bukkit.plugin.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(org.bukkit.plugin.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
public org.bukkit.plugin.Plugin plugin()- Specified by:
pluginin 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:
setLocalein interfaceILocalizer- Parameters:
language- language to be used
-
getMessage
Description copied from interface:ILocalizerGet a message.- Specified by:
getMessagein interfaceILocalizer- Parameters:
key- message key- Returns:
- message with replaced replacements if present.
-
setDefaultLocale
-
getMessage
- Specified by:
getMessagein interfaceILocalizer
-
getValue
- Specified by:
getValuein interfaceILocalizer
-
getMessage
- Specified by:
getMessagein interfaceILocalizer
-
getValue
- Specified by:
getValuein interfaceILocalizer
-
getValue
- Specified by:
getValuein interfaceILocalizer
-
localeBundle
- Specified by:
localeBundlein interfaceILocalizer
-
defaultBundle
- Specified by:
defaultBundlein interfaceILocalizer
-
localize
Translates a String with Placeholders. Can handle multiple messages with replacements.- Specified by:
localizein interfaceILocalizer- Parameters:
message- Message to translate- Returns:
- Replaced Messages
-
localize
Description copied from interface:ILocalizerTranslates a String with Placeholders. Can handle multiple messages with replacements. Add replacements in the right order.- Specified by:
localizein interfaceILocalizermessage- 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:
getIncludedLocalesin interfaceILocalizer- Returns:
- array of available locales.
-
includedLocales
Description copied from interface:ILocalizerReturns all available locales.- Specified by:
includedLocalesin interfaceILocalizer- Returns:
- set of registered locales.
-
addLocaleCodes
Description copied from interface:ILocalizerAdd 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:
addLocaleCodesin interfaceILocalizer- Parameters:
runtimeLocaleCodes- map with locales codes to add.
-
registerChild
- Specified by:
registerChildin interfaceILocalizer
-
builder(Plugin, String)