Jump to content

1.11 Messages don't translate outside of development environment.


Raycoms

Recommended Posts

    /**

    * Send a message to the player.

    * @param player the player to send to.

    * @param message the message to send.

    */

    public static void sendPlayerMessage(@NotNull final EntityPlayer player, final String message)

    {

        player.sendMessage(new TextComponentTranslation(message));

    }

 

We're using this to translate our strings.

It seems to work 100% inside intellij in smp and ssp.

 

But when I produce the jar it stops working.

In and ssp it just shows the english strings and in smp it does only show the placeholder strings.

Link to comment
Share on other sites

The server cannot do translation.  The server does not know what language the player has their client set to.  Translation can only occur on the client.

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

You're already sending a message to the client.  When it's received, translate it.  It may already even be passing through a translation step, you'd have to check.

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

It seems to work great in Intellij, But on the server it doesn't seem to work at all, strangely.

 

Strangely? There are many display things that only the client can or should do. Some confusions can be masked inside an IDE and/or SP because the client classes are present.

 

player.sendMessage(new TextComponentTranslation(message));

 

I suggest that you step into and through the TextComponentTranslation constructor (and any calls it might make to other methods). If/when you start to see it grabbing client-side data, then its place client-side should make more sense. I suspect that it is designed to let each client translate in its own way (e.g. into client-specific language), something the server can't do for multiple players.

 

Even looking at the way you call it, I can see that you expect it to do the same translation for every player before handing the message to a player-specific method. That alone is fishy.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

        new TextComponentTranslation(message).getFormattedText();

 

I have to use the above to get the formatedString on the client? For a GUI for example?

 

I will test something today, it's possible that something happens with the message string and it doesn't arrive correctly outside of intellij.

Link to comment
Share on other sites

Some more questions:

 

If I want to send the player something like "LanguageString1" + "LanguageString2" meaning both need separate translations can I do this like this:

 

new TextComponentTranslation(message1).appendSibling(new TextComponentTranslation(message2));

 

and if I want to append strings or integers like "LanguageString1" + "100" + "Oak logs" can I do it like this?:

 

new TextComponentTranslation(message1).appendString("100" + "Oak logs");

 

Link to comment
Share on other sites

Some more questions:

 

If I want to send the player something like "LanguageString1" + "LanguageString2" meaning both need separate translations can I do this like this:

 

new TextComponentTranslation(message1).appendSibling(new TextComponentTranslation(message2));

 

and if I want to append strings or integers like "LanguageString1" + "100" + "Oak logs" can I do it like this?:

 

new TextComponentTranslation(message1).appendString("100" + "Oak logs");

Why not just test it yourself?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Okay it seemed to work when I want to concatenate the strings

 

But If I want to format a string like this: tile.blockHutTownHall.messageColonistDead=The colonist %s has died at %d %d %d!

 

and I want to insert strings and integers I don't know how to do it yet =(

Link to comment
Share on other sites

Okay it seemed to work when I want to concatenate the strings

 

But If I want to format a string like this: tile.blockHutTownHall.messageColonistDead=The colonist %s has died at %d %d %d!

 

and I want to insert strings and integers I don't know how to do it yet =(

 

You do the %s and %d stuff in your lang file:

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/resources/assets/harderfarming/lang/en_US.lang#L1

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/farming/item/ItemButcherKnife.java#L37

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

If you look at the TextComponentTranslation class you'll see that it uses I18n.

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

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.



×
×
  • Create New...

Important Information

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