Class Translator
java.lang.Object
valorless.valorlessutils.translate.Translator
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDownloadLanguage
(String key) Downloads a language file from GitHub and saves it to the plugin's data folder.boolean
FileExists
(String key) Checks if the specified language file exists in the plugin's data folder.Reads the content of a language file.Gets the current language key.Loads the fallback language file from the plugin's data folder.void
SetLanguage
(String key) Sets the language for translation.Translates a given key to the corresponding language.
-
Constructor Details
-
Translator
Constructor for Translator class.- Parameters:
key
- The language key to initialize the translator with.
-
-
Method Details
-
Translate
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
Gets the current language key.- Returns:
- The current language key.
-
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
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
Sets the language for translation.- Parameters:
key
- The language key to set.
-
GetLanguageFileContent
Reads the content of a language file.- Parameters:
key
- The language key.- Returns:
- The content of the language file as a string.
-
DownloadLanguage
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.
-