This repository was archived by the owner on Nov 10, 2021. It is now read-only.
Repository navigation
Translations
Julian edited this page Aug 26, 2017
·
6 revisions
First create your/s messages class/es of this way:
public enum Messages1 implements LangInterface {
// You can create as many messages as you want
MESSAGE(
"&eEsto es un mensaje",
"&eThis is a message",
"&eDies ist eine Nachricht",
);
private final HashMap<Langs, String> locales = new HashMap();
/**
* Define the default languages to load
*
* @param es Spanish
* @param en English
* @param de German
*/
private DefineInfo(String es, String en, String de) {
this.locales.put(Langs.ES, es);
this.locales.put(Langs.EN, en);
this.locales.put(Langs.DE, de);
/* ... */
}
@Override
public String getText(Langs lang) {
// Get the messages translated
return StringsUtils.translateColors(getDefaultText(lang));
}
@Override
public String getDefaultText(Langs lang) {
Langs main = PluginBase.INSTANCE.getMainLanguage();
String v = LangManager.getValueFromFile(lang, this);
v = (v == null) ? this.locales.get(lang) : v;
v = (v == null) ? LangManager.getValueFromFile(main, this) : v;
v = (v == null) ? this.locales.get(main) : v;
return v;
}
}And now you have to boot the manager...
// List of main languages
LangManager.setKeys(Langs.ES, Langs.EN, Langs.DE);
// List of enums to load
LangManager.saveMessages(Messages1.class);
// Even you can select a custom path to save it by using...
LangManager.saveMessages("path", Messages1.class);
// By default it will created at <plugin_folder>/langs/
// Load the messages
LangManager.loadMessages();It will create three files into langs folder. For example, english messages would be like this:
# ######################################
# ## [LOCALES]Do not edit %variables% ##
# ######################################
MESSAGE: '&eThis is a message'Finally, you have to do this for getting the appropriate message.
// Get the appropriate message by passing the player locale
String translatedMessage = Messages1.MESSAGE.getText(Localizer.getLocale(player));
// And that's all, you got the message in the player's language.
player.sendMessage(translatedMessage);How to integrate:
How to use: