Class Translation

java.lang.Object
com.marcpg.libpg.lang.Translation

public class Translation extends Object
Provides easy translations based on simple .properties files.
Since:
0.0.6
  • Constructor Details

    • Translation

      public Translation()
  • Method Details

    • loadProperties

      public static void loadProperties(@NotNull @NotNull File folder) throws IOException
      Goes through all of the files inside the specified folder and loads them as Properties files into the translations.
      The translation files should follow the simple name scheme [language]_[COUNTRY].properties, so for example en_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 the FileInputStream.
    • loadProperties

      public static void loadProperties(@NotNull @NotNull Map<Locale,Properties> languages)
      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

      public static void loadSingleProperties(Locale locale, @NotNull @NotNull Properties properties)
      Loads a .properties file into the translations.
      Parameters:
      locale - The locale to load into the translations.
      properties - The properties object to load.
    • loadMaps

      public static void loadMaps(@NotNull @NotNull Map<Locale,Map<String,String>> maps)
      Goes through all of the maps and locales and saves them into the translations.
      Parameters:
      maps - All maps and their languages.
    • loadSingleMap

      public static void loadSingleMap(Locale locale, @NotNull @NotNull Map<String,String> map)
      Loads a Map file into the translations.
      Parameters:
      locale - The locale to load into the translations.
      map - The map object to load.
    • string

      public static String string(Locale locale, String key)
      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

      @NotNull public static @NotNull String string(Locale locale, String key, Object... variables)
      Gets the translation of a key as a string and replaces the placeholders with specified variables.
      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 api Component (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 api Component (TextComponent) and replaces the placeholders with specified variables.
      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

      @Nullable public static @Nullable Map<Locale,String> reverse(String value)
      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.