A Java library wich brings support for multiple languages to a Spigot plugin.
- Please ask anything about the plugin here.
- Always feel free to contact me on discord: @hekates
- Or contact me on X (twitter): @Hekates2
Step 1. Add the JitPack repository to your build file:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency:
<dependency>
<groupId>com.github.Hekates</groupId>
<artifactId>Languify</artifactId>
<version>v1.2-beta</version>
</dependency>
Step 1. Add the JitPack repository to your build file
Append this to the end of the repositories in your build.gradle file:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency:
dependencies {
implementation 'com.github.Hekates:Languify:v1.2-beta'
}
Of course it is also possible to install the library via downloading and implementing the jar using your IDE. The download to the jar binaries can be found here.
After implementing the library the next steps are as following:
package ch.hekates.example;
import ch.hekates.languify.Languify;
import ch.hekates.languify.language.LangLoader;
import ch.hekates.languify.language.Text;
import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin {
@Override
public void onEnable() {
//Setting up Languify (necessary)
Languify.setup(this, this.getDataFolder().toString());
LangLoader.saveLanguages("PluginName"); // Plugin name specified in the plugin.yml
Languify.setLanguage("en")
}
}
Create a folder called "lang" inside your resources folder in which you add a new json file named after the language you specified with Languify#setLanguage(String) in your Main class:
.
└── src/
└── main/
├── java/
└── resources/
└── lang/
└── en.json
The {language}.json file must contain following line:
{
"language": "English"
}
Of course you replace "English" with the name of your language.
To add and use new text in your plugin, add the key to the end of your json file followed by the text that should be displayed instead. To use the newly set text simply use the Text#get() method with the key as the input.
{
"language": "English",
"test-message": "Hello World"
}
package ch.hekates.example;
import ch.hekates.languify.Languify;
import ch.hekates.languify.language.LangLoader;
import ch.hekates.languify.language.Text;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Logger;
public final class Main extends JavaPlugin {
@Override
public void onEnable() {
Logger log = this.getLogger();
Languify.setup(this, this.getDataFolder().toString());
LangLoader.saveLanguages("ExamplePlugin");
Languify.setLanguage("en");
log.info(Text.get("test-message"));
}}
The JavaDocs for this project can be found here. If there are any questions left or if something doesn't work, please create an issue.