1.14.4 Get translated item name.

Discussion in 'Spigot Plugin Development' started by xDec0de_, Mar 30, 2020.

  1. So I want to get the spanish name of an item every time I pick it up, Is there any way to do this?

    I have been searching for hours and didn't found anything.

    Example: If I pickup dirt it will be named "Tierra".
  2. You can choose your language in Minecraft but there is no language support in spigot itself.
    You could look for a translator api but those are sometimes expensive or limited to a certain amount of words per time frame.
  3. You could get the player's locale and then from that rename every item he picks to match their his local
  4. Let's say I need it to put the name of the item in chat, in spanish.

    Checking every item? Minecraft has a lot of items...
  5. I think you would go best with printing out all item names and let a translator translate the list.
  6. Look into the Google Translate API. They have documentation for the Java language.
    It's also free (to my knowledge).
  7. Google translate API is fine, but some items will be mistranslated

    Ex: "Prismarine" will be "Prismarino" and it should be "Prismarina" :/

    For every minecraft item? That would take a ridiculous time that I don't have.
  8. Material.values() returns you an array of all the materials. You can loop through it and filter out the #isLegacy() ones and only allow the #isItem() ones and print the #name().replaceAll(“_”, “ “).toLowercase() of each one into the console and there you have your list to translate.
    You could run that piece of code in public static void main(String[]) {}
    so you can run this code directly in your IDE.
    #8 MightyOne, Mar 31, 2020
    Last edited: Mar 31, 2020
  9. However, making a translator every time a player picks up any item won't be laggy?
  10. My suggestion would be to map the translations to the materials somewhere once and forever.
    • Agree Agree x 1
  11. Is there any way to do this with minecraft lang files? (It's for a private plugin, this won't be published)
  12. If you really want you can go looking for the minecraft lang files. I found an interesting thread about how to find them: link
    You will probably also end up just mapping the whole translation to each material because the the material names int the files are a bit different to the spigot ones. But you can try. The language you are looking for is probalby not sk_sk but rather es_es
    • Useful Useful x 1
  13. Any way to get the item name string? ex: item.swordIron.name

    Maybe changing the string? IRON_SWORD, I can only think about removing _, lower case it and add "item." at the beginning, then ".name" at the end, so it will be something like "item.ironsword.name" but I don't know how to reverse the words.
  14. This worked on 1.8, but I am pretty sure this also works on 1.14.4:
    Convert the item to an NMS item
    Code (Java):
    net.minecraft.server.v1_14_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
    Then you can call the method "getName()" on it and get the bare, untranslated name.

    NOTE: This WILL return the display name if the item has one. To not get the display name use "nmsItem.getItem().g(nmsItem)" instead (< THIS METHOD IS NOT TESTED, JUST CHECKED THE DECOMPILED SOURCE)
  15. Got this code:

    Code (Text):
    net.minecraft.server.v1_14_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
    TranslatableComponent comp = new TranslatableComponent(nmsItem.getItem().g(nmsItem).toString());
    But got this message:

  16. What if you put it inside a regular text component?

    Code (Java):
    TextComponent main = new TextComponent("");
  17. Same :/


    Code (Text):
                TranslatableComponent comp = new TranslatableComponent(nmsItem.getItem().g(nmsItem).toString());
                TextComponent main = new TextComponent("");
  18. Any difference if you use getText() or getString() instead of toString()?

    Or use CraftChatMessage.fromComponent(); ?