Package revxrsal.commands.locales
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 TypeMethodDescriptionvoid
add
(@NotNull ResourceBundle resourceBundle) Registers the given resource bundlevoid
add
(@NotNull LocaleReader reader) Adds the given locale reader to this translator.void
addResourceBundle
(@NotNull String resourceBundle) Adds the given resource bundle.void
addResourceBundle
(@NotNull String resourceBundle, @NotNull Locale... locales) Adds the given resource bundle.static @NotNull Translator
create()
Creates a newTranslator
@NotNull String
Returns the message that corresponds to the given key, using the currentgetLocale()
.@NotNull String
Returns the message that corresponds to the given key, using the given locale.@NotNull Locale
Gets the current, default locale used by this translatorvoid
Sets the locale of this translator.
-
Method Details
-
create
Creates a newTranslator
- Returns:
- The newly created translator
-
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.
-
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
-
addResourceBundle
void addResourceBundle(@NotNull @NotNull String resourceBundle, @NotNull @NotNull Locale... locales) Adds the given resource bundle. This will only register for the givenLocale
s.For example, if you have the following files:
- foo_en_US.properties
- foo_fr.properties
- foo_de.properties
Locales.ENGLISH
,Locales.FRENCH
andLocales.GERMAN
.- Parameters:
resourceBundle
- Resource bundle to registerlocales
- Locales to register for
-
addResourceBundle
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
- Parameters:
resourceBundle
- Resource bundle to register
-
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
-