Localisation tutorials ?

Discussion in 'Plugin Development' started by Chloe-chan, Mar 3, 2013.

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

    Chloe-chan

    I am currently coding my plugin and I am thinking of ways to improve it. I then thought, why not do some localisation. I then thought I can hard code the translated files, but I want to know if there is any way easier. Thanks for any help. :D
     
  2. Offline

    Tirelessly

    Say you have a lang.yml file and a config.yml. Your lang file will have something like:
    Code:
    English:
        no-permission: "You don't have permission!"
        invalid-argument: "Invalid arguments!"
    Spanish:
        no-permission: "Tu no tienes spanishWordforPermission!"
        invalid-argument: "I don't know spanish well!"
    
    Then, in onEnable, you assign global variables to the values. Example:
    Code:java
    1.  
    2. public void onEnable(){
    3. String lang = getConfig().getString("lang");
    4. this.noPermsMessage = langYml.getString(lang+"no-permission");
    5. this.invalidArg = langYml.getString(lang+"invalid-argument");
    6. }
    7.  


    Hope this helps.
     
    Wizardo367 likes this.
  3. Offline

    minoneer

    The easiest way (appart from hard coding it) would be to use the config.yml file. You could load all messages (and other information) from there, allowing your users to even customize those.

    Depending on the size of your plugin, you can get a bit more fancy and create one (or more) new file.yml, which are dedicated to localisation.
     
  4. Offline

    Tirelessly

    Note that there should be a period at the beginning of the lang+"section" areas, but if i edit it i'll lose all the spacing D:

    EDIT: minoneer 's solution is probably better, just allowing completely custom messages.
     
  5. Offline

    Chloe-chan

    Okay, I'll try and see how it goes.
     
  6. Offline

    minoneer

    good luck :)
     
  7. Offline

    Chloe-chan

    One question, how to make it automatically generate the files ?

    EDIT: The language file.
     
  8. Offline

    minoneer

  9. Offline

    Chloe-chan

    Thanks ! ^^
     
Thread Status:
Not open for further replies.

Share This Page