LangAPI

Logo

The Language API

This plugin API has been made for plugin developpers, to let them have a lang.yml file in the plugin, in which all the messages sent to players are written. It makes then a new folder in the LangAPI one, where 5 files are created, one for each available language (en/us, fr, it, de, es). Then the server owner says, with a command, that he's server is, for example, german. Then LangAPI will automatically use all the german files, and use them for the messages. You can also directly put a german language file in the plugin.yml, here for example de.yml, and this plugin will copy it in the same folder : it's already translated.

How to implement it

If you are a plugin developper, you must add 2 lines at the start of the onEnable() method (preferably after the saveDefaultConfig() ) :

this.getServer().getPluginManager().callEvent(new LangAPIImplementationEvent(this));
api = LangAPI.getAPI(this);

and define 'api' as an APIPlugin :

private APIPlugin api;

How to use it in your code

To get a message from your lang file, juste type :

api.getTranslator().getString("path.to.string"); // It takes a string from the lang file

The string is selected in all the plugins files when the language is selected. For example, if the server said, language is french, then it will take it from the fr.yml file in the plugin folder in the LangAPI one. There are many features available, and others that will be added in the next versions.

The final code example, copy it if you want :

private APIPlugin api;

@Override
public void onEnable() {
	this.getServer().getPluginManager().callEvent(new LangAPIImplementationEvent(this));
	api = LangAPI.getAPI(this);
}

How to make the translation be easier

If you have people that can translate the texts from your plugin, then create a file for each language in which it is translated (en.yml for English, de.yml for German, fr.yml for French, it.yml for Italian, es.yml for Spanish...). It will copy them directly, and the server owner will not have to translate them directly.

How to change the server language

With a command : /lang <lang_id> (without < and >) : translation is instantly made.

In the config.yml file : lang: lang_id : translation made after reload.

Available languages

For the moment, only these languages are avaiblable :

  • English : lang_id = en
  • German: lang_id = de
  • French: lang_id = fr
  • Italian: lang_id = it
  • Spanish: lang_id = es

Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    61636
  • Created
    Jul 16, 2013
  • Last Released File
    Jul 16, 2013
  • Total Downloads
    745
  • License

Categories

Members

Recent Files

Bukkit