Skip to content

Render translatable arguments and children #1226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

TonytheMacaroni
Copy link
Contributor

@TonytheMacaroni TonytheMacaroni commented May 4, 2025

This is an attempt at fixing #1157.

Currently, it renders translation arguments & children components twice when using MessageFormat translations - not exactly sure on the best approach for avoiding this.

@TonytheMacaroni
Copy link
Contributor Author

TonytheMacaroni commented May 5, 2025

Extracted out the parent component rendering to avoid rendering translation arguments & child components twice. Noticed, however, that this PR still does not account for rendering named arguments - not sure how it should be done w.r.t. the virtual components. For example, this test would fail:

@Test
public void testRecursiveNamedArguments() {
    assertEquals(
        Component.text("Kezz is cool!"),
        this.translate(
            Component.translatable(
                "<name> is <thing>!",
                Argument.component("name", Component.translatable("<arg:0>", Component.text("Kezz"))),
                Argument.component("thing", Component.translatable("<arg:0>", Component.text("cool")))
            )
        )
    );
    assertEquals(
        Component.text("Kezz is cool!"),
        this.translate(
            Component.translatable(
                "<arg:0> is <arg:1>!",
                Argument.component("name", Component.translatable("<arg:0>", Component.text("Kezz"))),
                Argument.component("thing", Component.translatable("<arg:0>", Component.text("cool")))
            )
        )
    );
}

@TonytheMacaroni
Copy link
Contributor Author

Fixed another issue, where translatable tags in MiniMessage translations aren't passed through the global translator.

@kezz kezz added this to the 4.22.0 milestone May 21, 2025
@zml2008 zml2008 enabled auto-merge June 17, 2025 14:14
@zml2008 zml2008 added this pull request to the merge queue Jun 17, 2025
@zml2008 zml2008 self-assigned this Jun 17, 2025
Merged via the queue into KyoriPowered:main/4 with commit 96bdab1 Jun 17, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants