Jump to content

on TranslationTextComponent append variable


Spring

Recommended Posts

i try:

    @Override
    @OnlyIn(Dist.CLIENT)
    public void appendHoverText(ItemStack itemStack, @Nullable World world, List<ITextComponent> textComponents,
                                ITooltipFlag tipFlag) {
        if (itemStack.getTag() != null) {
            textComponents.add(new TranslationTextComponent("tooltip.chinacraft.silk_worm.schedule",10));
        }
    }

No effect, he didn't append variables behind mine

Link to comment
Share on other sites

first do never use @OnlyIn, since it's only for vanilla
second, do you want to have the '10' as replacement for your TranslationTextComponent?
-> if yes, that's not how the TranslationTextComponent worked, you need to put the Translation into the language file
-> if not, explain what you mean by 'he didn't append variables behind mine'

Link to comment
Share on other sites

7 hours ago, Luis_ST said:

first do never use @OnlyIn, since it's only for vanilla
second, do you want to have the '10' as replacement for your TranslationTextComponent?
-> if yes, that's not how the TranslationTextComponent worked, you need to put the Translation into the language file
-> if not, explain what you mean by 'he didn't append variables behind mine'

This is my language file

 

I also have a custom variable, I want to splice it to the back of the language file to make it look like this: Growth progress: 20

 

"tooltip.chinacraft.silk_worm.schedule": "§aGrowth progress: ",

 

    @Override
    public void appendHoverText(ItemStack itemStack, @Nullable World world, List<ITextComponent> textComponents,
                                ITooltipFlag tipFlag) {
        if (itemStack.getTag() != null) {
            textComponents.add(new TranslationTextComponent("tooltip.chinacraft.silk_worm.schedule"));
        }
    }

 

I am curious how it is implemented in the code.
Or do I need to implement it in the language file?

 

I use translation software, if you don’t understand, I’m sorry

Edited by Spring
Link to comment
Share on other sites

8 hours ago, Spring said:

I also have a custom variable, I want to splice it to the back of the language file to make it look like this: Growth progress: 20

19 hours ago, Spring said:
new TranslationTextComponent("tooltip.chinacraft.silk_worm.schedule",10)

this is correct but the translation should look like this:

"tooltip.chinacraft.silk_worm.schedule": "Growth progress: %s"

 

8 hours ago, Spring said:

§a

do not use color codes, use IFormattableTextComponent#mergeStyle

  • Thanks 1
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.