This repository was archived by the owner on Nov 10, 2021. It is now read-only.
Repository navigation
Translations
Julian edited this page Sep 30, 2016
·
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) {
return StringsUtils.translateColors(getDefaultText(lang)); // Get the messages translated
}
@Override
public String getDefaultText(Langs lang) {
String value = (this.locales.get(lang) == null)
? this.locales.get(PluginBase.INSTANCE.getMainLanguage()) : this.locales.get(lang);
String v = LangManager.getValueFromFile(lang, this);
return (v == null) ? value : 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/ [Check out to "LANG_DIRECTORY" constant]
// 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'How to integrate:
How to use: