[Tutorial] Let your plugin support multiple language

Discussion in 'Resources' started by bramhaag, Mar 4, 2014.

Thread Status:
Not open for further replies.
  1. Hi all,

    This is my 2nd plugin tutorial and I'm going to show you how to let your plugin support messages from different languages located in the config

    Why this is handy?
    If you are a server owner, you could just change 1 option in the config so the messages are in your language, instead of editing every single message.

    How to config should look:
    language: enUs
        message: 'This is a message'
        #Idk how to write stuff in france...
        message: 'Message la France'
    The code to send a message:
    1. p.sendMessage(this.getConfig().getString("lang." + plugin.getConfig().getString("language") + "." + "message")

    Code explanation:

    p.sendMessage = sends a message to something with the value of 'p'. In this code, a Player
    this.getConfig() = gets the config
    getString() = get the String from the config
    . = Go down in the named section (e.g "lang." would get the enUS and frFR lists)

    Well, this was it for this tutorial.

    Garris0n likes this.
  2. Offline


    You should be a little bit more in-depth in your tutorial, but it was overall decent.

    In a tutorial you should explain the applications of what you are trying to teach!

    For example, why can I, the server owner, just not put a message into the language I need? Where does this configurability come in really handy?
  3. AoH_Ruthless
    Wow, i didn't thing about this before. Thanks, i will add it!
  4. Offline


    I'm currently trying a new type of "Multiple-Languages"
    The players set their own language with an Item or a Command and then it will be detectet on all BungeeCord servers using MySQL... If just someone could help me with MySQL.... :(
  5. Offline


    This is NOT MySQL my dear :D
  6. Wombosvideo

    I watched this video series a while ago, but i'm quite sure that he saves stuff in a MySQL server

    Here, some SQL. This will help you

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 7, 2016
  7. Offline


    Thanks.. I will try it...
    If I can make it work I will give you my codes :)
  8. Offline


    Doing it with a "Message" enum and a "Language" enum would be better, something like...
    Message.A_MESSAGE.send(player, Language.ENGLISH_US);
  9. Garris0n

    I never understand emuns. Maybe this is even better:

    public static void multiMessage(Player player, String message)
    p.sendMessage(this.getConfig().getString("lang." + plugin.getConfig().getString("language") + "." + message);

    So you can do className.multiMessage(p, "message");
  10. Offline


    Enums would probably be better (efficiency wise).

    They are pretty straightforward and I would recommend the Online Documentation for a quick and easy teaching.
  11. Offline


    I wouldn't even find it a matter of efficiency, it's just a far nicer format to use. Defined constants are way better to use than arbitrary strings (especially in an IDE where auto-complete is a thing).
  12. Offline


    Wait, do you even know that one word, just one word in French? bonjour
  13. xTrollxDudex

    Well i do know that word, but i did not really think about that...
  14. Offline


    If you forget, there is always google translate :)
  15. :p
Thread Status:
Not open for further replies.

Share This Page