Class Translation

java.lang.Object
net.hectus.lang.Translation

public class Translation extends Object
Provides easy translations based on simple .properties files.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull net.kyori.adventure.text.Component
    component(Locale locale, String key)
    Gets the translation of a key as a adventure api Component (TextComponent).
    static @NotNull net.kyori.adventure.text.Component
    component(Locale locale, String key, Object... variables)
    Gets the translation of a key as a adventure api Component (TextComponent) where all placeholders are replaced with the specified variables.
    static void
    load(@NotNull File langFolder)
    Goes through all of the files inside plugins/Invade/lang/ and loads them as properties files into the translations.
    static String
    string(Locale locale, String key)
    Gets the translation of a key as a string.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Translation

      public Translation()
  • Method Details

    • load

      public static void load(@NotNull @NotNull File langFolder) throws IOException
      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 the FileInputStream.
    • 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 and 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 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 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 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 api Component (TextComponent) where all placeholders are replaced with the 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 and just the key if the translation wasn't found.