feat: allow template strings #65
base: master
Are you sure you want to change the base?
Conversation
This change allows the use of template strings with variables within translated configurations. It looks for translations that explicitly begin with `"\`` and end with `\`"` Configuration JSON: ``` { "HelloMessage": "`Hello ${userName}`" } ``` Usage: ``` const userName = 'International User'; const message = __('HelloMessage'); ``` Expected output when rendering message: `Hello International User`
Codecov Report
@@ Coverage Diff @@
## master #65 +/- ##
==========================================
+ Coverage 95.12% 95.23% +0.11%
==========================================
Files 4 4
Lines 82 84 +2
Branches 23 23
==========================================
+ Hits 78 80 +2
Misses 4 4
Continue to review full report at Codecov.
|
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.
Can we add tests?
I think I've added the appropriate tests for template strings. Please let me know what you think. Thank you kindly. It looks like there is some confusion about who I am on Github for the CLA. I used the website to submit the change initially and then I used git commit commands to submit the tests, but if you click through on the test commits you will see its still me. I suspect there is a delay in reconciling the CLA. |
@scottcanoni Does the email address you're currently using for your github account and the one you use in your |
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.
👍 Thx
@@ -6,6 +6,7 @@ describe('apply-translations', () => { | |||
beforeAll(() => { | |||
const translations = { | |||
'static-key': 'translated static key', | |||
'template-string': '`Your dynamic value is ${variableForTemplateString}.`', // eslint-disable-line no-template-curly-in-string |
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.
Please move the eslint-disable
comment to the top
/* eslint-disable
no-template-curly-in-string,
*/
@michael-ciniawsky I think the CLA bot just took time to re-check. I added my additional email address and verified it under my Github profile and after some time, I see that the CLA bot has marked it as signed. Also, I moved the eslint disable comment to the top of the file. |
@evilebottnawi are the tests that I added adequate? I am not sure how to resolve this issue on the continuous integration environment: |
That's unrelated to this PR and should be fixed by #64 instead. Just needs sign-off from 1-2 more maintainers and g2g imho |
@evilebottnawi and @michael-ciniawsky, now that the unit tests are there, can this be merged? |
This change allows the use of template strings with variables within translated configurations. It looks for translations that explicitly begin with:
and end with
Configuration JSON:
Usage:
Expected output when rendering message:
Hello International User