Jump to content

[1.12.2] Sending Localized Messages to a Player


Codasylph

Recommended Posts

In my mod there are a number of times when a message is sent to the player's chat to say something like "Good job you did this thing, now you can do this other thing!" or "That didn't quite work, you should make sure all the blocks are in the right place." I want this messages to able to be changed via the mod's lang files so that someone playing the game in spanish gets a message in spanish, english gets english, etc. Currently I do this by calling something like this on the server side: 

player.sendMessage(new TextComponentString(DemConstants.ALTAR_CREATED));

and the variable ALTAR_CREATED is defined like this:

public static final String ALTAR_CREATED = I18n.format("text.altar_created.message");

and the string "text.altar_created.message" is in my .lang file as whatever I actually want it to be.  I currently only have a US English version, but I'm trying to plan ahead.

 

This all works just dandy in single player mode, but when I attempt to run it on a dedicated server I get a NoClassDef error because I18n is client side only.  To my knowledge EntityPlayer#SendMessage is *supposed* to be called on the server side.

 

So, clearly what I'm doing is wrong. What should I be doing?

Edited by Codasylph
Link to comment
Share on other sites

Send the unlocalized text to the client and make the client translate it. That's the only way.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

26 minutes ago, Draco18s said:

Send the unlocalized text to the client and make the client translate it. That's the only way.

But.. but how? ?

 

So, for anyone who stumbles across this thread in the future, I actually figured out how shortly after I made this post, proving that if i'd spent a few more minutes with google I would never have needed to post at all. If you use TextComponentTransation instead of TextComponentString it does the translating on the correct side. example:

player.sendMessage(new TextComponentTranslation("text.altar_created.message"));

 

No I18n or anything

Edited by Codasylph
Link to comment
Share on other sites

18 hours ago, Draco18s said:

Send the unlocalized text to the client and make the client translate it. That's the only way.

 

17 hours ago, Codasylph said:

If you use TextComponentTransation instead of TextComponentString it does the translating on the correct side. example:


player.sendMessage(new TextComponentTranslation("text.altar_created.message"));

 

No I18n or anything

This looks like your sending a message translated on the server (ie in the server’s language) to the client where it will appear in the sever’s language. Don’t do this, lang files exists for a reason

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

13 minutes ago, Cadiboo said:

translated on the server (ie in the server’s language)

The server has no concept of translation(or language at all for that matter). What OP did is the correct way. It send the lang key to the client and the client then translates it with the language the client has selected.

Link to comment
Share on other sites

1 minute ago, V0idWa1k3r said:

The server has no concept of translation(or language at all for that matter). What OP did is the correct way. It send the lang key to the client and the client then translates it with the language the client has selected.

Really sorry, I read “new ITextComponentTranslation()” as “localise()”

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.