I think localization is important. I’m from germany and there are many servers with german chat, and plugins should be localized as well.
It would be nice to have a simple system for translation and maybe even a unified message (color) formatting system, making translation of big text-heavy plugins simple.
I thought about it when making Bukkit plugins, and i think it should work like gettext. The good thing about it is that the code is still readable, without placeholders for messages like “PLAYER_KILL_MESSAGE”.
//untranslated simple plugin
onlinePlayer.sendMessage(String.format("%1$s was killed by %2$s", victimPlayer.getName(), killPlayer.getName()));
//another example: plural handling
int kills = 3;
if(kills == 1)
onlinePlayer.sendMessage("You killed one player.");
else
onlinePlayer.sendMessage(String.format("You killed %1$d players!", kills));
//translated version
I18n i18n = I18nFactory.getI18n(getClass());
onlinePlayer.sendMessage(i18n.tr("{0} was killed by {1}", victimPlayer.getName(), killPlayer.getName()));
//plural handling
int kills = 3;
System.out.println(i18n.trn("You killed one player.", "You killed {0} players!", 2, kills));
Translation Maps:
And now you can create a translation that maps all the strings to other strings:
German Translation file example:
{0} was killed by {1} ---> {1} hat {0} getötet
You killed one player. ---> Du hast einen Spieler getötet.
You killed {0} players! ---> Du hast {0} Spieler getötet!
When a translation for a string was not found in a language map, it uses the hardcoded one and displays a warning in the console (“Missing message in translation DE…”)
Multi-Language servers:
The Minecraft client sends the used client language to the server. That means there could be an option to display messages in that language, or permissions could be used for that…
Or the whole server uses one config-defined language.
Alternative language config (fallback):
When a plugin is not available in the selected language, have a fallback map:
EN_us <---> EN
DE_de <---> DE
DE ---> EN
PIRATE_SPEAK ---> EN
Translation registration
To provide a translation, just use something like:
//set hardcoded language
plugin.setDefaultLocale(Locale.EN)
//add a translation
plugin.addTranslation(Locale.DE, translationMapFromFile)
Translators can make translation pack plugins that use the method above on other plugins:
//Worldedit German Language Pack Plugin
Plugin worldEditPlugin = server.getPlugin("WorldEdit");
if(worldEditPlugin != null) worldEditPlugin.addTranslation(Locale.RU, translationMapFromFile)
Formatting and line breaks
The translation API could be extended to unify the color formatting of messages:
maybe using a xml/html syntax for message translations:
<success>Game started by {0}. Use <cmd>/guess <letter></cmd></success>
<br/>
<info>
{1} <hearts>{2}</hearts>
<br/>
<cmd>/hangman hide</cmd> to disable this...
</info>
With a tag to color/format map:
success: {
color: light-green
}
info: {
color: yellow
}
hearts: {
bold: true,
color: dark-red
}
cmd: {
color: gold
}
Admins can edit these files to modify the message formatting of a plugin…