Class DatLocalisation
java.lang.Object
com.datdeveloper.datmoddingapi.localisation.DatLocalisation
A utility for serverside localisation
Does not yet support providing arguments
Does not yet support providing arguments
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLocalisation
(String key, String translation) Add a localisation to the available translations.void
Clear all the translations
Warning, this clears ALL the translations, from all mods that have registered up until this point.net.minecraft.network.chat.Component
getComponent
(String key, Object... args) Get a localisation as a component
The component will be formatted using DatChatFormattingstatic DatLocalisation
Get Returns the DatLocalisation instance.getLocalisation
(String key) Get a localised string from the storegetLocalisation
(String key, String fallback) Get a localised string from the store, returning the fallback if it doesn't existvoid
loadLocalisations
(String localeFilePath) Load in a JSON file of localisations from a file
First checks filepath, then checks classpath
Keys already in the table will be overridden.void
removeTranslation
(String key) Remove the translation with the matching keyvoid
removeTranslations
(Predicate<String> predicate) Remove any translations that match the given predicate
-
Method Details
-
getInstance
Get Returns the DatLocalisation instance.- Returns:
- the DatLocalisation instance
-
loadLocalisations
Load in a JSON file of localisations from a file
First checks filepath, then checks classpath
Keys already in the table will be overridden.
Bad keys will be discarded with an error printed to console
The locale file is expected to be a json file, containing a single object that maps strings to strings
The keys of this locale file are expected to match the regex: ^([\w-])\.([\w-](?:\.[\w-])+)$Essentially, a key is made of 2 or more parts consisting of numbers, letters, underscore and dashes, where each part is separated by a ".". The first part is intended to be an identifier for the mod that uses the translation, however this is not enforced.
- Parameters:
localeFilePath
- The path on the classpath to the locale file containing the translations- Throws:
FileNotFoundException
- Thrown when the given locale path cannot be foundIOException
- Thrown when the file at the given locale path experiences a failure during reading
-
addLocalisation
Add a localisation to the available translations.If the key is already in the table then it will be overridden.
- Parameters:
key
- The key of the translationtranslation
- The translation
-
getLocalisation
Get a localised string from the store- Parameters:
key
- The key of the localised string- Returns:
- The localised string
-
getComponent
Get a localisation as a component
The component will be formatted using DatChatFormatting- Parameters:
key
- The key of the localised messageargs
- Arguments used for formatting the component- Returns:
- A formatted chat component
- See Also:
-
getAllTranslations
-
getLocalisation
Get a localised string from the store, returning the fallback if it doesn't exist- Parameters:
key
- The key of the localised stringfallback
- The string to return if the key isn't in the store- Returns:
- The localised string or the fallback
-
clearTranslations
public void clearTranslations()Clear all the translations
Warning, this clears ALL the translations, from all mods that have registered up until this point. This method was mainly added for testing reasons, so don't go misusing it.
If you really need to clear some translations, you should probably useremoveTranslation(String)
orremoveTranslations(Predicate)
- See Also:
-
removeTranslation
Remove the translation with the matching key- Parameters:
key
- The key of the translation to remove- See Also:
-
removeTranslations
Remove any translations that match the given predicate- Parameters:
predicate
- The predicate that determines if a key should be removed- See Also:
-