Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

    /**

    * 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.

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.

  • Author

So we will have to send a message to the client and ask for the translation for each translation we want to do?

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.

  • Author

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

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.

  • Author

        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.

  • Author

Yes I want both and I just found out that I'm sending some additional info in the message string sometimes. That's why it doesn't translate some messages on the server.

Will take care of that.

 

Thanks for the help.

  • Author

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");

 

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.

  • Author

Because everything always works great in intellij.

I'd have to build the jar, host a server on my laptop, start the client and test it like this with every change I make.

  • Author

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 =(

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.

  • Author

But shouldn't I translate it with the TextComponentTranslation instead of the:  "I18n.format"

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.