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 unescape logic, expression props, and ICU format for Trans component #892

Merged
merged 4 commits into from
Aug 23, 2023

Conversation

nicegamer7
Copy link
Contributor

@nicegamer7 nicegamer7 commented Aug 22, 2023

Why am I submitting this PR

After #871, it seems I introduced a regression, though it did help find a bug.

It seems that react-i18next does indeed default the key to the defaults prop (I added a comment to prevent anyone from making the same mistake again). I've reverted the changes from #871 to match react-i18next's behavior. After reporting this on react-i18next's bug tracker (i18next/react-i18next#1663), it looks like this was unintended. I fixed that, so no need to revert #871.

Otherwise, it seems we had a bug where we were unescaping values in reverse (i.e. unescaping when it wasn't needed, and not unescaping when it was needed). I corrected this, and also made it so that we always unescape the key, since this matches react-i18next's behavior as well.

Does it fix an existing ticket?

Closes #886.

Checklist

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

@nicegamer7 nicegamer7 changed the title revert #871; fix unescape logic for Trans component Revert #871; Fix unescape logic for Trans component Aug 22, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (5fdd776) 93.95% compared to head (e7c7325) 93.97%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #892      +/-   ##
==========================================
+ Coverage   93.95%   93.97%   +0.01%     
==========================================
  Files          11       11              
  Lines        1836     1841       +5     
==========================================
+ Hits         1725     1730       +5     
  Misses        111      111              
Files Changed Coverage Δ
src/lexers/jsx-lexer.js 98.49% <100.00%> (+0.02%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nicegamer7
Copy link
Contributor Author

nicegamer7 commented Aug 22, 2023

Actually, I'm going to put this on hold until i18next/react-i18next#1663 is resolved, since it might mean we don't have to revert #871.

edit: i18next/react-i18next#1663 was fixed, so there's no need to revert #871 anymore.

@nicegamer7 nicegamer7 marked this pull request as draft August 22, 2023 17:40
@nicegamer7 nicegamer7 changed the title Revert #871; Fix unescape logic for Trans component Fix unescape logic for Trans component Aug 22, 2023
@nicegamer7 nicegamer7 marked this pull request as ready for review August 22, 2023 18:41
assert.equal(Lexer.extract(content)[0].key, "I'm Cielquan")
done()
})

it('supports the shouldUnescape options', (done) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this a little counter intuitive and confusing. I would expect that shouldUnescape would unescape the defaultValue. If I understand correctly, that's not the case in react-18next, is that right?

Also, I'm wondering if we should add a test with a i18nKey property with escaped value. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a little confusing, but I'll try to explain as I understand it.

The shouldUnescape option means that after the translation is loaded/displayed, it will be unescaped. That's why when we see the shouldUnescape option, we don't unescape when extracting, so that it can be unescaped by react-i18next when it is loaded/displayed.

Also, I think it makes sense to add a test for a i18nKey with an escaped value, nice suggestion.

@nicegamer7 nicegamer7 changed the title Fix unescape logic for Trans component Fix unescape logic, expression props, and ICU format for Trans component Aug 23, 2023
@nicegamer7
Copy link
Contributor Author

Hey @karellm, I just pushed another commit that fixes two more issues that I noticed. The two issues are:

  1. Extracting Trans components with the ICU format was broken
  2. Extracting props with object/array expressions was broken

Take a look when you have a chance and let me know if there are any concerns!

@karellm karellm merged commit a9f4467 into i18next:master Aug 23, 2023
4 checks passed
@karellm
Copy link
Member

karellm commented Aug 23, 2023

LGTM! Thanks for the great work and it is now deployed as 8.7.0

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.

Keys extracted with escaped characters starting in v8.4.0
3 participants