Skip to content
This repository was archived by the owner on Feb 22, 2026. It is now read-only.

Fix self-closing tag to match with react-i18next#663

Open
yoo2001818 wants to merge 1 commit intoi18next:masterfrom
yoo2001818:br-tag
Open

Fix self-closing tag to match with react-i18next#663
yoo2001818 wants to merge 1 commit intoi18next:masterfrom
yoo2001818:br-tag

Conversation

@yoo2001818
Copy link

Why am I submitting this PR

This PR corrects the behavior of <br /> to match with react-i18next's nodeToString routine.

When transSupportBasicHtmlNodes is true, inside <Trans>, react-i18next converts <br /> into <br/>. But i18next-parser converts <br /> into <br />, causing a difference between the defaultValue generated with each other.

If i18nKey is specified, this wouldn't cause any problem because only defaultValue would differ, and both <br/> and <br /> can be parsed well by react-i18next.

However, if only defaultValue is specified, the defaultValue will be used as the i18nKey. Therefore it makes generated key and the actual key to mismatch, making react-i18next unable to find the translation entry.

Does it fix an existing ticket?

No

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • tests are included and pass: yarn test (see details here)
  • documentation is changed or added

FYI) I've encountered a failing test while running tests. I investigated the problem, and it turned out that Intl.PluralRules defaults to the system language if an unknown locale is specified - so the test will fail if the system language is set to other languages that have more/less than 2 plural types.

(Intl.PluralRules is used by i18next.PluralResolver.)

The test can be successfully run by changing the system language to en-US:

LANG='en-US' yarn test
  1) parser
       options
         generates one plural key for unknow languages:

      Uncaught AssertionError: expected { 'test {{count}}_other': '' } to deeply equal { 'test {{count}}_one': '', …(1) }
      + expected - actual

       {
      +  "test {{count}}_one": ""
         "test {{count}}_other": ""
       }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant