Class Translator

java.lang.Object
valorless.valorlessutils.translate.Translator

public class Translator extends Object
  • Constructor Details

    • Translator

      public Translator(String key)
      Constructor for Translator class.
      Parameters:
      key - The language key to initialize the translator with.
  • Method Details

    • Translate

      public String Translate(String translationKey)
      Translates a given key to the corresponding language.
      Parameters:
      translationKey - The key to be translated.
      Returns:
      The translated string or the original key if translation is not available.
    • GetLanguageKey

      public String GetLanguageKey()
      Gets the current language key.
      Returns:
      The current language key.
    • LoadFallbackLanguage

      public String LoadFallbackLanguage()
      Loads the fallback language file from the plugin's data folder. If the file doesn't exist, it is copied from the plugin's resources.
      Returns:
      The content of the fallback language file, or null if an error occurs.
    • FileExists

      public boolean FileExists(String key)
      Checks if the specified language file exists in the plugin's data folder.
      Parameters:
      key - The name of the language file (without the extension).
      Returns:
      true if the language file exists, false otherwise.
    • SetLanguage

      public void SetLanguage(String key)
      Sets the language for translation.
      Parameters:
      key - The language key to set.
    • GetLanguageFileContent

      public String GetLanguageFileContent(String key)
      Reads the content of a language file.
      Parameters:
      key - The language key.
      Returns:
      The content of the language file as a string.
    • DownloadLanguage

      public String DownloadLanguage(String key)
      Downloads a language file from GitHub and saves it to the plugin's data folder.

      This method fetches the language file from a specified GitHub URL and saves it in the plugin's data folder. It also ensures the necessary directories are created and logs the success or failure of the download.

      Parameters:
      key - The name of the language file (without the extension).
      Returns:
      The content of the downloaded language file as a string, or null if an error occurs during the download or reading process.