Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant