Translate Plugins

Discussion in 'Plugin Development' started by killer999999, Jun 4, 2013.

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

    killer999999

    Hello.
    Please write here how to translate plugins.
    Please i need!!

    Thanks
     
  2. If you are trying to translate one of your own plugins but you don't know how to start then I suggest you to google for: eclipse how to externalize strings. If you are trying to translate other plugins then I suggest you to ask their original creator or use a progrem like DirtyJoe to open the jar and change the strings to the language you want, most plugins will not allow you to spread the changed jar.
     
  3. As CaptainBern said: if you want to translate plugins that are coded by others you will need to ask them for translations.
    But if you want to translate your own plugin you could save the texts in HashMaps with a key.
    There would be one hashmap for each supported language:
    Code:
    Map<String, String> translationEN = new HashMap<>();
    translationEN.add("welcome", "Welcome to this server!");
    translationEN.add("bye", "Goodby!");
    Map<String, String> translationDE = new HashMap<>();
    translationDE.add("welcome", "Willkommen am server!");
    translationDE.add("bye", "Tschüss! Komm bald wieder!");
    
    Then you could save the wished translation in a temporary hashmap.
    Do something like this:
    Code:
    Map<String, String> usedTranslation;
    switch(config.getString("language") {
         case "EN": usedTranslation = translationEN;
         case "DE": usedTranslation = translationDE;
    }
    
    And when a translation is needed simply get the string from the usedTranslation hashmap.
    Code:
    player.sendMessage(usedTranslation.get("welcome"));
    
     
  4. Why not just: (in eclipse) Source>Externalize Strings.. ? Okey the code will look for strings in a file that is in the jar but with basic java you are able to edit that so it will take a look at a file in the plugin's datafolder...
     
  5. I think your users will like my way better because it's easier in FTP to edit a bukkit config file.
    It's not very comfortable to edit files inside of a .jar file in FTP
     
  6. Re-read my post please.
     
  7. google
    translate
     
    CaptainBern likes this.
  8. Sorry. I don't know about eclipse's Externalize Strings option.
    But if you already know it, why do you ask?
     
  9. Im facepalming on this one, I just told about it, you say: yeah file in jar stuff, I said: re-read > if you did that you would know I also said you can edit the location of the messages file so it will get the file from the dataFolder and not from within the jar. (datafolder = getDataFolder())
    ;D
     
    InspectorFacepalm likes this.
  10. Oh painful xD
    I thought you were the one who has started this thread.
    I think I should go and sleep now.
     
    CaptainBern likes this.
  11. Haha lawl...
     
  12. Offline

    ZeusAllMighty11



    Terrible idea. Google translate is one of the worst sources, you can learn more from a school than you can from there
     
    StealerSlain likes this.
  13. Offline

    ampayne2

    Of course you can; Schools are for learning, Google translate is for translating. I doubt you can find a better way to translate text without having actual experts on every language that you pay to instantly translate for you.
    I like the idea said above with the hashmaps, except instead of using .put hundreds of times, there should be separate .yml files, one for each language. Then on startup it loops through each one, putting the entries in the hashmap.
     
  14. Offline

    gidonyou


    I tried Same Thing and made my other class called Mafia Translation:

    Code on MafiaTranslation.java
    Show Spoiler

    Code:java
    1. package me.gidonyou.mafiaeasy;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5.  
    6.  
    7. public class MafiaTranslation {
    8.  
    9. MafiaEasy plugin;
    10. public MafiaTranslation(MafiaEasy instance) {
    11. plugin = instance;
    12. }
    13.  
    14. public void translate(){
    15. plugin.TransEN.put("helpItem", "/mafia item -- Give Item that Register Mafia");
    16. plugin.TransEN.put("helpStart", "/mafia start -- Enable Killing");
    17. plugin.TransEN.put("helpClear", "/mafia clear -- Clear Mafia List");
    18. plugin.TransEN.put("mafiasBlood", ChatColor.RED + "Mafia's Blood");
    19. plugin.TransEN.put("registerMafia", "Right Click This To Register That Your "+ ChatColor.DARK_RED + "Mafia!");
    20. plugin.TransEN.put("noPerm", ChatColor.DARK_RED + "You Don't Have Permission!");
    21. plugin.TransEN.put("mafiaCleared", "Mafia Cleared!");
    22. plugin.TransEN.put("needMafia", ChatColor.DARK_RED + "[Warning] " + ChatColor.RED + "You need least 1 Mafia!");
    23. plugin.TransEN.put("gameStartCit", ChatColor.RED + "Game Started, Kill or Run Away from Mafia");
    24. plugin.TransEN.put("gameStartMaf", ChatColor.RED + "Game Started, Kill every Citizen");
    25.  
    26. plugin.TransEN.put("mafiaSel", ChatColor.RED + "Mafia Selected");
    27. plugin.TransEN.put("mafiaSelError", ChatColor.RED + "Game Aready Started!");
    28.  
    29. plugin.TransEN.put("mafiaKilledPVM", ChatColor.RED + "Mafia is Dead");
    30. plugin.TransEN.put("mafiaRespawn", ChatColor.GOLD + "[Warning] "
    31. + ChatColor.YELLOW + "Mafia is Respawning");
    32. plugin.TransEN.put("citizenKick", ChatColor.DARK_RED + "Your Died");
    33. plugin.TransEN.put("gameDidntStart", ChatColor.DARK_RED + "Game Haven't Started!");
    34. //plugin.TransEN.put("", );
    35.  
    36.  
    37.  


    because i did not wanted to make a mess on my main class,

    Main Class

    Show Spoiler

    Code:java
    1. public class MafiaEasy extends JavaPlugin {
    2. protected MafiaTranslation mafiaTranslation;
    3. public final Map<String, String> TransEN = new HashMap<String, String>();
    4. public final Map<String, String> TransKR = new HashMap<String, String>();
    5.  
    6. public final MafiaTranslation mt = mafiaTranslation;
    7.  
    8. Map<String, String> usedTranslation;
    9.  
    10.  
    11.  
    12. public void onEnable() {
    13. TransEN.put("Hello", "Hello"); // add to hashmap manually in main class
    14. Lang = getConfig().getString("Language");
    15.  
    16. switch (getConfig().getString("Language")) {
    17. case "EN":
    18. usedTranslation = TransEN;
    19. case "KR":
    20. usedTranslation = TransKR;
    21. }
    22. }
    23.  
    24. public boolean onCommand(CommandSender sender, Command command,
    25. String label, String[] args) {
    26. if (label.equalsIgnoreCase("hi")) {
    27. if (args.length == 0) {
    28.  
    29. sender.sendMessage(usedTranslation.get("Hello"));
    30.  
    31. } else if (args[0].equalsIgnoreCase("test")) {
    32.  
    33. }
    34. }
    35.  




    and Error.log
    Show Spoiler

    2014-02-04 21:55:23 [WARNING] Unexpected exception while parsing console command "hi"
    org.bukkit.command.CommandException: Unhandled exception executing command 'hi' in plugin MafiaPVP vAlpha 0.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
    at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServer.java:523)
    at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchServerCommand(CraftServer.java:512)
    at net.minecraft.server.v1_5_R3.DedicatedServer.an(DedicatedServer.java:262)
    at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:227)
    at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
    at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
    at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
    at org.bukkit.craftbukkit.v1_5_R3.command.ColouredConsoleSender.sendMessage(ColouredConsoleSender.java:55)
    at me.gidonyou.mafiaeasy.MafiaEasy.onCommand(MafiaEasy.java:92)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 8 more


    How can i fix this?
     
  15. gidonyou It looks like you have a class called MafiaEasy. Please post that class as well.
     
  16. Offline

    TeeePeee

    gidonyou
    You forgot to add breaks in your switch. En language falls through to kr and you don't have the entry set, so it tries to send a null message.
     
  17. Offline

    gidonyou

    Umm, I have included.. Mainclasss
     
  18. Offline

    TeeePeee

    gidonyou
    I don't know whether you didn't see my answer or you just didn't acknowledge it but you need to do this:
    <syntax=JAVA>case "EN":
    usedTranslation = TransEN;
    break;
    case "KR":
    usedTranslation = TransKR;
    break;</syntax>
    A non breaking case statement with just fall through to the next.
     
Thread Status:
Not open for further replies.

Share This Page