Skip to content

Can't use a number as index on .rich #1871

Open
@razzeee

Description

@razzeee

Description

Trying to port from next-i18n right now.

Having some trouble with the <Trans /> Component

For e.g. we have a translation like this

"contribute-languages": "All diese Übersetzungen wurden durch die Community ermöglicht. Falls du helfen möchstest bei der Übersetzung von Flathub, <1>tritt dem Flathub Übersetzer-Team bei</1>."

If I try to render it like

<p className="pt-8">
          {t.rich("contribute-languages", {
            1: (chunks) => (
              <a
                target="_blank"
                rel="noreferrer"
                className="no-underline hover:underline"
                href="https://hosted.weblate.org/engage/flathub/"
              >
                {chunks}
              </a>
            ),
          })}
        </p>

It fails with

Error: INVALID_MESSAGE: UNMATCHED_CLOSING_TAG
    at Languages (pages/languages.tsx:45:13)
  43 |         </ul>
  44 |         <p className="pt-8">
> 45 |           {t.rich("contribute-languages", {
     |             ^
  46 |             1: (chunks) => (
  47 |               <a
  48 |                 target="_blank" {
  code: 'INVALID_MESSAGE',
  originalMessage: 'UNMATCHED_CLOSING_TAG'
}

If I change the 1 to t it starts to work.

Verifications

Mandatory reproduction URL

https://github.com/razzeee/next-intl-repro

Reproduction description

Steps to reproduce:

  1. Open page
  2. See errors in log and nothing is translated

Expected behaviour

It should be translated

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream-issueThis issue is caused by an upstream dependency (e.g. Next.js)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions