Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

feat: allow template strings #65

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

scottcanoni
Copy link

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

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`
@jsf-clabot
Copy link

jsf-clabot commented Nov 1, 2017

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Nov 1, 2017

Codecov Report

Merging #65 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/index.js 94.44% <100%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd32318...1985fee. Read the comment docs.

Copy link
Member

@alexander-akait alexander-akait left a 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?

@scottcanoni
Copy link
Author

scottcanoni commented Nov 2, 2017

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.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Nov 2, 2017

@scottcanoni Does the email address you're currently using for your github account and the one you use in your .gitconfig differ ? The CLA Bot thinks you're two different entities in this case and you need to change the commit author of your commits to match to github email address

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a 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
Copy link
Member

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,
*/

@scottcanoni
Copy link
Author

@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.

@scottcanoni
Copy link
Author

@evilebottnawi are the tests that I added adequate?

I am not sure how to resolve this issue on the continuous integration environment:
The command "npm --version" failed and exited with 1 during .

@michael-ciniawsky
Copy link
Member

ERROR: npm is known not to run on Node.js v4.3.2

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

@scottcanoni
Copy link
Author

@evilebottnawi and @michael-ciniawsky, now that the unit tests are there, can this be merged?

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

Successfully merging this pull request may close these issues.

None yet

4 participants