Package com.marcpg.libpg.lang
Class Translation
java.lang.Object
com.marcpg.libpg.lang.Translation
Provides easy translations based on simple
.properties
files.- Since:
- 0.0.6
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull net.kyori.adventure.text.Component
Gets the translation of a key as an adventure apiComponent
(TextComponent
).static @NotNull net.kyori.adventure.text.Component
Gets the translation of a key as an adventure apiComponent
(TextComponent
) and replaces theplaceholders
with specifiedvariables
.static void
Goes through all of the maps and locales and saves them into the translations.static void
loadProperties
(@NotNull File folder) Goes through all of the files inside the specified folder and loads them asProperties
files into the translations.static void
loadProperties
(@NotNull Map<Locale, Properties> languages) Goes through all of the properties and loads them as.properties
files into the translations.static void
loadSingleMap
(Locale locale, @NotNull Map<String, String> map) Loads aMap
file into the translations.static void
loadSingleProperties
(Locale locale, @NotNull Properties properties) Loads a.properties
file into the translations.Reverse searches through all languages and all their values, to find out in what language and under what key this translation can be found.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 theplaceholders
with specifiedvariables
.
-
Constructor Details
-
Translation
public Translation()
-
-
Method Details
-
loadProperties
Goes through all of the files inside the specified folder and loads them asProperties
files into the translations.
The translation files should follow the simple name scheme[language]_[COUNTRY].properties
, so for exampleen_US.properties
.- Parameters:
folder
- 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
.
-
loadProperties
Goes through all of the properties and loads them as.properties
files into the translations.- Parameters:
languages
- All the properties files and their languages.
-
loadSingleProperties
Loads a.properties
file into the translations.- Parameters:
locale
- The locale to load into the translations.properties
- The properties object to load.
-
loadMaps
Goes through all of the maps and locales and saves them into the translations.- Parameters:
maps
- All maps and their languages.
-
loadSingleMap
Loads aMap
file into the translations.- Parameters:
locale
- The locale to load into the translations.map
- The map object to load.
-
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 or just the key if the translation wasn't found.
-
string
Gets the translation of a key as a string and replaces theplaceholders
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 or 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 an 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 or 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 an adventure apiComponent
(TextComponent
) and replaces theplaceholders
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 or just the key if the translation wasn't found.
-
reverse
Reverse searches through all languages and all their values, to find out in what language and under what key this translation can be found.- Parameters:
value
- The translation to search from. Can be any language.- Returns:
- A map with all the locales and keys that the translation is found at. Null if the reverse search didn't give any results.
-