Class DatLocalisation

java.lang.Object
com.datdeveloper.datmoddingapi.localisation.DatLocalisation

public class DatLocalisation extends Object
A utility for serverside localisation
Does not yet support providing arguments
  • Method Details

    • getInstance

      public static DatLocalisation getInstance()
      Get the DatLocalisation instance
      Returns:
      The DatLocalisation instance
    • loadLocalisations

      public void loadLocalisations(String localeFilePath) throws IOException
      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 found
      IOException - Thrown when the file at the given locale path experiences a failure during reading
    • addLocalisation

      public void addLocalisation(String key, String translation)
      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 translation
      translation - The translation
    • getLocalisation

      public String getLocalisation(String key)
      Get a localised string from the store
      Parameters:
      key - The key of the localised string
      Returns:
      The localised string
    • getAllTranslations

      public Map<String,String> getAllTranslations()
    • getLocalisation

      public String getLocalisation(String key, String fallback)
      Get a localised string from the store, returning the fallback if it doesn't exist
      Parameters:
      key - The key of the localised string
      fallback - 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 use removeTranslation(String) or removeTranslations(Predicate)
      See Also:
    • removeTranslation

      public void removeTranslation(String key)
      Remove the translation with the matching key
      Parameters:
      key - The key of the translation to remove
      See Also:
    • removeTranslations

      public void removeTranslations(Predicate<String> predicate)
      Remove any translations that match the given predicate
      Parameters:
      predicate - The predicate that determines if a key should be removed
      See Also: