Package net.hectus.lang
Class Translation
java.lang.Object
net.hectus.lang.Translation
Provides easy translations based on simple
.properties
files.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull net.kyori.adventure.text.Component
Gets the translation of a key as a adventure apiComponent
(TextComponent
).static @NotNull net.kyori.adventure.text.Component
Gets the translation of a key as a adventure apiComponent
(TextComponent
) where all placeholders are replaced with the specifiedvariables
.static void
Goes through all of the files inside plugins/Invade/lang/ and loads them as properties files into the translations.static String
Gets the translation of a key as a string.static @NotNull String
Gets the translation of a key as a string and replaces the placeholders with specifiedvariables
.
-
Constructor Details
-
Translation
public Translation()
-
-
Method Details
-
load
Goes through all of the files inside plugins/Invade/lang/ and loads them as properties files into the translations.
Will create the directories automatically for you, if not already there.
The translation files follow the simple name scheme [language]_[COUNTRY].properties, so for example en_US.properties.- Parameters:
langFolder
- The folder in which all the translation files are stored.- Throws:
IOException
- if the language folder doesn't exist or there was an error while creating theFileInputStream
.
-
string
Gets the translation of a key as a string.- Parameters:
locale
- The language to get the key from. Will use en_US by default, if the locale wasn't found.key
- What translation to get from the locale's translations.- Returns:
- The translation if everything worked and just the key if the translation wasn't found.
-
string
Gets the translation of a key as a string and replaces the placeholders with specifiedvariables
.- Parameters:
locale
- The language to get the key from. Will use en_US by default, if the locale wasn't found.key
- What translation to get from the locale's translations.variables
- The variables that replace the placeholders, in the order {0};{1};{2};...- Returns:
- The translation with all placeholders replaced with the variables if everything worked and just the key if the translation wasn't found.
-
component
@NotNull public static @NotNull net.kyori.adventure.text.Component component(Locale locale, String key) Gets the translation of a key as a adventure apiComponent
(TextComponent
).- Parameters:
locale
- The language to get the key from. Will use en_US by default, if the locale wasn't found.key
- What translation to get from the locale's translations.- Returns:
- The translation if everything worked and just the key if the translation wasn't found.
-
component
@NotNull public static @NotNull net.kyori.adventure.text.Component component(Locale locale, String key, Object... variables) Gets the translation of a key as a adventure apiComponent
(TextComponent
) where all placeholders are replaced with the specifiedvariables
.- Parameters:
locale
- The language to get the key from. Will use en_US by default, if the locale wasn't found.key
- What translation to get from the locale's translations.variables
- The variables that replace the placeholders, in the order {0};{1};{2};...- Returns:
- The translation with all placeholders replaced with the variables if everything worked and just the key if the translation wasn't found.
-