Internationalization 2.0

Translate your plugins more easier than ever

  1. Rafoudiablol
    Native Minecraft Version:
    1.16
    Tested Minecraft Versions:
    • 1.15
    • 1.16
    What does this library ?

    This library allow you to externalize all of your messages without annoying code to link them to the code. The goal is to avoid repetitive codes. The link is transparent, nice to use, almost no repetitive-code, and logged if translations are missing.

    What does NOT this library :
    This library will not translate alone your plugin. You must provide your translations or let your users to translate it.


    This library allow you to localize your plugin to any language by setting the config value of your config.yml, under reserve of the corresponding YAML file exists. You can also don't translate your plugin, but this library would allow your users to translate it and/or provide their own custom messages, and externalize your messages, not re-invent the wheel and keep your code clean. So only good.


    Because an example is worth a thousand words, an example plugin is available here.

    Features

    • Positional arguments with syntax ${1}, ${2}, etc.
    • Named arguments with syntax ${pluginName}, etc
    • Compile-time invalid arguments detection
    • Translate automatically Players to their username.

    Notes

    • It's not a plugin but a standalone library, so no need to add it to the plugin folder.

    Step-by-step

    For any precision, refer to the example plugin.
    1. Add a new entry to your config.yml as lang: en.
    2. Create the resource file lang/en.yml you fill with
      Code (YAML):
      welcome: Hello, message from the plugin ${1}
    3. Add this class to your plugin.
      Code (Java):
      package org.author.mypluginname
      public interface Example {
          String welcome(String pluginName);
      }
    4. Instanciate your messaging system with
      Code (Java):

      Example i18n = PluginLocalization.create(this, Example .class);
      getLogger().info(i18n.welcome("MySuperPlugin"));
    5. Already done. When calling any of the method of the interface, the corresponding message will be translated.

    To change the language without changing any code, you can do the following

    Code (YAML):

    # config/lang_zh.yml
    welcome
    : 您好,来自${1}插件的消息
     
    Code (YAML):

    # config.yml
    # It's the config file of your plugin.
    # It won't have to be empty,
    # but you just need to add this entry,
    # defaulted to "en" if it does not exists.

    lang
    : zh
     
    Done!

    Bonus

    Define named arguments:

    Code (Java):

    package org.author.mypluginname;

    import fr.rafoudiablol.internationalization.core.Arg;

    public interface Example {
        String welcome(@Arg("pluginName") String pluginName);
    }
     
    Add this annotation to each of your arguments you want to name. It's probably a good idea to give the same name as the code argument.

    Why need to do this? Because java can't get arguments named, they are hidden once compiled.