Developers
This is a guide on how to use DragonTranslations in development of a plugin.
Here is some example code to get started on translating:
@Plugin(...)
public class ExamplePlugin() {
@Inject
private PluginContainer pluginContainer;
@Inject
@ConfigDir(sharedRoot = false)
private Path configDir;
public static Translator translator;
public void onPreInit(GamePreInitializationEvent event) {
//Creates a translator of the type ConfigurableTranslator, with the specified locale as the default locale.
ConfigurableTranslator confTranslator = new ConfigurableTranslator(this, configDir.resolve("lang/"), Locales.EN_US);
//Adds a new translation key with the specified locale
confTranslator.addTranslation(Locales.EN_US, "player.command.success", Text.of(TextColors.GREEN, "You have successfully sent a command"));
//Adds a new Locale to this translator
confTranslator.createLangFile(Locales.JA_JP);
//Translator variable to easily access and translate messages.
translator = confTranslator;
}
@Listener
public void onCommand(SendCommandEvent event, @First Player player) {
player.sendMessage(translator.translate(player.getLocale(), "player.command.success"));
}
}