Package dev.demeng.pluginbase.locale
Interface Translator
public interface Translator
Represents a translator. A translator allows localizing messages, adding bundles, registering
custom locales, and changing the default locale.
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(@NotNull LocaleReader reader) Adds the given locale reader to this translator.voidadd(@NotNull ResourceBundle resourceBundle) Registers the given resource bundlevoidaddResourceBundle(@NotNull ClassLoader loader, @NotNull String resourceBundle) Adds the given resource bundle.voidaddResourceBundle(@NotNull ClassLoader loader, @NotNull String resourceBundle, @NotNull Locale... locales) Adds the given resource bundle.default voidaddResourceBundle(@NotNull String resourceBundle) Adds the given resource bundle from the current class loader.default voidaddResourceBundle(@NotNull String resourceBundle, @NotNull Locale... locales) Adds the given resource bundle from the current class loader.voidaddResourceBundleFromFolder(@NotNull String resourceBundle) Adds the given resource bundle from "/locales" in the plugin data folder.voidclear()Clears all currently registered locales.booleancontainsKey(@NotNull String key) Returns whether this translator contains a localized message for the given key, using the currentgetLocale().booleancontainsKey(@NotNull String key, @NotNull Locale locale) Returns whether this translator contains a localized message for the given key.static @NotNull Translatorcreate()Creates a newTranslator@NotNull StringReturns the message that corresponds to the given key, using the currentgetLocale().@NotNull StringReturns the message that corresponds to the given key, using the given locale.default @NotNull String @NotNull []Returns the message array that corresponds to the given key, using the currentgetLocale().default @NotNull String @NotNull []Returns the message array that corresponds to the given key, using the given locale.@NotNull LocaleGets the current, default locale used by this translatorvoidSets the locale of this translator.
-
Method Details
-
create
Creates a newTranslator- Returns:
- The newly created translator
-
containsKey
Returns whether this translator contains a localized message for the given key, using the currentgetLocale().- Parameters:
key- Key to check for- Returns:
trueif this translator has a localized message for the key
-
containsKey
Returns whether this translator contains a localized message for the given key.- Parameters:
key- Key to check forlocale- Locale to check in- Returns:
trueif this translator has a localized message for the key
-
get
Returns the message that corresponds to the given key, using the currentgetLocale(). If no such message is found, the key will be returned.- Parameters:
key- Message key to fetch with- Returns:
- The translated message, or the key if not found.
-
get
Returns the message that corresponds to the given key, using the given locale. If no such message is found, the key will be returned.- Parameters:
key- Message key to fetch withlocale- Locale to get with- Returns:
- The translated message, or the key if not found.
-
getArray
Returns the message array that corresponds to the given key, using the currentgetLocale(). Useful for multi-line translations such as item lore. If no such message is found, a single-element array containing the key will be returned.- Parameters:
key- Message key to fetch with- Returns:
- The translated message array, or a single-element array of the key if not found.
-
getArray
@NotNull default @NotNull String @NotNull [] getArray(@NotNull @NotNull String key, @NotNull @NotNull Locale locale) Returns the message array that corresponds to the given key, using the given locale. Useful for multi-line translations such as item lore. If no such message is found, a single-element array containing the key will be returned.- Parameters:
key- Message key to fetch withlocale- Locale to get with- Returns:
- The translated message array, or a single-element array of the key if not found.
-
add
Adds the given locale reader to this translator.- Parameters:
reader- The locale reader to add
-
add
Registers the given resource bundle- Parameters:
resourceBundle- Resource bundle to register
-
addResourceBundleFromFolder
Adds the given resource bundle from "/locales" in the plugin data folder. This will only register for the givenLocales.For example, if you have the following files:
- foo_en_US.properties
- foo_fr.properties
- foo_de.properties
Locales.ENGLISH,Locales.FRENCHandLocales.GERMAN.- Parameters:
resourceBundle- Resource bundle to register
-
addResourceBundle
void addResourceBundle(@NotNull @NotNull ClassLoader loader, @NotNull @NotNull String resourceBundle, @NotNull @NotNull Locale... locales) Adds the given resource bundle. This will only register for the givenLocales.For example, if you have the following files:
- foo_en_US.properties
- foo_fr.properties
- foo_de.properties
Locales.ENGLISH,Locales.FRENCHandLocales.GERMAN.- Parameters:
loader- Class loader for the bundleresourceBundle- Resource bundle to registerlocales- Locales to register for
-
addResourceBundle
void addResourceBundle(@NotNull @NotNull ClassLoader loader, @NotNull @NotNull String resourceBundle) Adds the given resource bundle. This will automatically check for all locales inLocales.For example, if you have the following files:
- foo_en_US.properties
- foo_fr.properties
- foo_de.properties
Locales.ENGLISH,Locales.FRENCHandLocales.GERMAN.- Parameters:
loader- Class loader for the bundleresourceBundle- Resource bundle to register
-
clear
void clear()Clears all currently registered locales. -
getLocale
Gets the current, default locale used by this translator- Returns:
- The default locale
-
setLocale
Sets the locale of this translator.- Parameters:
locale- The locale of this translator
-
addResourceBundle
default void addResourceBundle(@NotNull @NotNull String resourceBundle, @NotNull @NotNull Locale... locales) Adds the given resource bundle from the current class loader.- Parameters:
resourceBundle- Resource bundle to register- See Also:
-
addResourceBundle
Adds the given resource bundle from the current class loader.- Parameters:
resourceBundle- Resource bundle to register- See Also:
-