Jump to content

[1.18.2] Unable to use '%' sign in localization strings with placeholders


H4kt

Recommended Posts

I've added a string to my lang my as follows:

{
  "gui.<modid>.test": "Test percent sign {0}%%",
}

I'm then trying to render that string in a menu screen as follows:

override fun render(
  stack: PoseStack,
  mouseX: Int,
  mouseY: Int,
  delta: Float
) {
	
  font.draw(
    stack,
    TranslatableComponent("gui.<modid>.test", 10)
    x, y
    1
  )
    
}

However this akwardly results in string being rendered as: Test percent sign {0}%
Is there any way to get percent sign to work with placeholders?

Edited by H4kt
wrong tabulation
Link to comment
Share on other sites

Translatable components only support String substitutions/formatting and minecraft uses the java.util.Formatter format.

https://forge.gemwire.uk/wiki/Internationalization

https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html

 

Your lang file should look something like:

Test percent sign %s%%
Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

1 hour ago, warjort said:

Translatable components only support String substitutions/formatting and minecraft uses the java.util.Formatter format.

https://forge.gemwire.uk/wiki/Internationalization

https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html

 

Your lang file should look something like:

Test percent sign %s%%

Formatting like {n} also works, but not with percentage sign
Replacing {0} with %s seems to work
Thank you for your help

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.