-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(trans): allow interpolation in tOptions if provided #1204
feat(trans): allow interpolation in tOptions if provided #1204
Conversation
@jamuhl As written on Twitter this morning, I would work on this after work 😃, I am really excited 🥳 This would be my very first OSS contribution 🎉 |
@jamuhl I have no clue why it is messing with my PR here https://codeclimate.com/github/i18next/react-i18next/pull/1204 🤔 , if anyone else has any clues, would love some assistance 🙌 |
Do I need to update the documentation in https://github.com/i18next/react-i18next-gitbook, if so, what exactly should I update related to |
src/Trans.js
Outdated
@@ -298,6 +298,7 @@ export function Trans({ | |||
...interpolationOverride, | |||
defaultValue, | |||
ns: namespaces, | |||
...tOptions?.interpolation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to change line 293 to add the passed in tOptions.interpolation like:
const interpolationOverride = values ? tOptions?.interpolation : { interpolation: { ...tOptions?.interpolation, prefix: '#$?', suffix: '?$#' } };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamuhl @adrai I did the changes as requested 💯, one issue though, it still seems not to be escaping HTML tags properly. Here is a screenshot when using I wonder if there is a way to Also what do you think of the changes so far? What should I do next? Many thanks 🙏 💕 |
@tigerabrodi maybe you missed my first comment about optional chaining ( regarding the test: I suspect react is already escaping your |
@adrai I actually implemented the change @jamuhl suggested #1204 (comment), should I try again, but without optional chaining? What would the next steps be, since this seems not to be working? |
@adrai I pushed a new commit without Optional chaining 👏 |
removal of optional chaining is ok, thx but the unescape issue is a react problem 🤷♂️ I'm not a react expert, maybe someone knows more? |
It could possibly be a test environment issue.
@kentcdodds Any other thoughts on this? #1204 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest switching to React Testing Library eventually, but maybe this is the issue?
test/trans.render.spec.js
Outdated
const stringWithHTMLTags = '<no>Hello'; | ||
const TestElement = () => ( | ||
<Trans tOptions={{ interpolation: { escapeValue: true } }}> | ||
<div> {stringWithHTMLTags} </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<div> {stringWithHTMLTags} </div> | |
<div>{stringWithHTMLTags}</div> |
Maybe the extra spaces are the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't even notice the spaces! 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try this first, thanks both of you 💕
probably it's an enzyme issue... @tigerabrodi if it works for you in react, I think if this can't be fixed with enzyme, we can skip the test or if you like you can try to switch to a better react test library? |
@adrai You mean for that particular test use React Testing Library? Or convert the whole project to use React Testing Library, which I would actually be down to 😃 ? My suggestion: Try out what @kentcdodds mentioned, if it still does not work, skip the test and merge the changes, and I would with joy and passion convert this project to use React Testing Library instead of Enzyme, which could take some time 👍. Side question: @adrai I was wondering if this project plans on migrating fully to TypeScript? If so, I'd also be down to help in every way I can 🎉. We use it at work by the way, and you and @jamuhl are just really awesome, being able to contribute here just means the world to me 😃 💕. |
@tigerabrodiI would say, if you really like to change all tests to "React Testing Library" try it 😉 about TypeScript, idk, maybe not, need to wait for @jamuhl answer tomorrow morning. |
@adrai Is it okay to merge the changes I made in I would make a fixup commit and squash the commits, so we only have the changes in In a separate PR, I would start the conversion to React Testing Library 🎉. I plan on doing it with @JacobMGEvans, we really look forward to it 💕 🤩 PS. What @kentcdodds pointed out was not the issue 👍. |
Good job @tigerabrodi :) |
4d59b6a
to
d8043dc
Compare
@adrai I pushed the last commit 🙌 Do I still need to change anything or? I am excited about @jamuhl 's feedback. Once this gets merged, huge celebration haha 🍾, funny though, my sister has birthday on Friday, what a coincidence, two celebrations in a row 😂 😃. In another PR, I would start the conversion to React Testing Library 🎉 💕 |
lgtm |
Looks awesome 👍... a great first contribution...keep it up...we're all happy to get help. Regarding the encoding. This comes from react which does a good job of guarding people against accidentally pass unencoded user input into the page (XSS attacks): So it comes to two options a dev has to insert translations into a page: a) using dangerouslysetinnerhtml https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml A little hard to simply describe how the Trans component works / can be used -> which might be a cause of some pain: i18next/react-i18next-gitbook#15 So while this PR fixes an issue - I guess, it will not solve the initial problem you liked to solve. You might open an issue with the content you like to get translated and we might help out with some options on how to use the Trans component for it. Regarding the switch to Switching completely to typescript is something we considered - @adrai started work on a successor for the current i18next implementation - first in typescript but on the way, we decided to no go further with typescript as it felt more like a burden than a win (not sure it's a lack of our understanding of typescript or really just the price you pay for types, idk). |
Thank you for your contribution - looking forward to see more from you - well done. This fix was published in react-i18next@11.7.4 |
@jamuhl hahaha, wohooo 🍾 🎉, you are awesome, I will never forget this moment nor you 🙌 💕 |
@jamuhl I think regarding TypeScript, that would not be necessary, but React Testing Library, wohooo 🎉, that'd be really awesome, my friends are also down to help me out @kentcdodds @JacobMGEvans and many more 💕 Thank you again @jamuhl, really, my first step into OSS, I admire it so much, I look up to so many, @kentcdodds himself is one of my greatest inspiration and role model, this really means the world to me, I look forward to my long journey here on github haha 😃 💯 🎉 🍾 |
@jamuhl Regarding the issue we have at work, I would open an issue for that and try to explain it as thoroughly as possible, thank you again, and thank you @adrai also, you guys have no idea how much this means to me!!! 💕 Regarding converting to React Testing Library, that is the least I can do, someday we will all meet up in a React conf hopefully hahaha. This really means so much to me, more than every single birthday that I have had and will have 😃 🎉 |
@jamuhl Regarding the conversion over to React Testing Library, friends from @kentcdodds Discord also wanna help out 🥳. I plan on opening the PR on Friday, and from there magic will happen 😃 💯, I look forward to it, coding with friends is always awesome 😄. Thanks to you and @adrai, my first big step into OSS 💕 |
Checklist
npm run test