Multiple language support YML system

Discussion in 'Plugin Development' started by alex123099, Mar 10, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    alex123099

    Hi guys,
    For my plugins many people have been asking me to create a translated version, so I was thinking of implementing a "set your messages" config file and use the strings set in the config file as the messages for my plugins.

    I have a general idea of how to implement this system, but could someone who has done this before explain how the system should work? I'm not asking for code, just sort of the algorithm for it.

    Thanks in advance.
     
  2. Offline

    tommycake50

  3. Offline

    Panjab

    For a multiple language support I'd recommend XML.
     
  4. Offline

    alex123099

    tommycake50
    I didn't ask what to use for the system, I asked how the system should work.

    Panjab
    Hmm, why XML?
     
  5. Offline

    1Rogue Retired Staff

    Have a yaml file, and then a .sendMessage(CommandSender sender, String path) method in the YAML handler class you create. Then whenever you want to send a message, just notify the language handler:

    Code:java
    1. public void sendMessage(CommandSender sender, String path) {
    2. sender.sendMessage(this.yaml.getString(path));
    3. }


    Where "yaml" would be whatever language file you load.
     
    alex123099 likes this.
  6. Offline

    alex123099

    1Rogue
    This is the simplest solution I've seen!
    I've been thinking of pre-loading all the messages into final constants in a LanguageHandler, and then use them when sending messages, but your method seems a lot simpler.
     
  7. Offline

    1Rogue Retired Staff


    YAML files are already loaded into memory, so that would be somewhat pointless to do.
     
  8. Offline

    TheE

    Java has a build in API for localizations, Resource Bundles. The system is extremely flexible and automatically cached, but a bit more difficult to setup. I wrote a full implementation for YAML files for MyWarp, so if you want to check it out you might take a look here.

    The implementation consists of three classes: the YamlResourceBundle is the basic implementation of the ResourceBundle. It loads the underlying YamlFile into Java's logic using bukkit's API (and enforces UTF-8 encoding on the file to support special characters). The ResourceBundleControl controls how java manages the individual resource bundles, meaning where it looks for a file, what file-types are acceptable (yaml only), etc. The LocalizationManager ties everything together and provides methods to get the translated string (plus, via reflection, use the player's client local to get the string).
     
Thread Status:
Not open for further replies.

Share This Page