-
Notifications
You must be signed in to change notification settings - Fork 592
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
improve i18n parser to support console-extensions.json #8363
improve i18n parser to support console-extensions.json #8363
Conversation
4708778
to
5a574a4
Compare
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.
Looks good to me. Just one comment about a console.log that looked like it may not be intentional. Thanks for cleaning up the linter file and making some of the other scripts easier to read.
frontend/i18n-scripts/lexers.js
Outdated
JSON.parse(content, (key, value) => { | ||
if (typeof value === 'string') { | ||
const match = value.match(/%(.+)%/); | ||
console.log('testing:', match[1]); |
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.
Was this console.log intentional?
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.
Most likely it's just to test the lexer as it was developed, I think we can remove it now.
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.
removed
globals: { | ||
process: 'readonly', | ||
'no-console': 'off', | ||
// fs.promises requires a newer version of node however our compliance is set to node >=10 |
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.
FYI once #7306 is merged, our compliance will be Node.js >= 14.
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.
right, but not there yet :P
frontend/i18n-scripts/i18n-to-po.js
Outdated
), | ||
); | ||
) | ||
.catch((e) => console.error(e, fileName)); |
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.
.catch((e) => console.error(e, fileName)); | |
.catch((e) => console.error(fileName, e)); |
We can print context-specific bits (like fileName
) before printing error & its stack trace.
frontend/i18n-scripts/i18n-to-po.js
Outdated
language, | ||
), | ||
) | ||
.catch((e) => console.error(e, fileName)); |
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.
.catch((e) => console.error(e, fileName)); | |
.catch((e) => console.error(fileName, e)); |
frontend/i18n-scripts/lexers.js
Outdated
try { | ||
JSON.parse(content, (key, value) => { | ||
if (typeof value === 'string') { | ||
const match = value.match(/%(.+)%/); |
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.
const match = value.match(/%(.+)%/); | |
const match = value.match(/^%(.+)%$/); |
frontend/i18n-scripts/lexers.js
Outdated
JSON.parse(content, (key, value) => { | ||
if (typeof value === 'string') { | ||
const match = value.match(/%(.+)%/); | ||
console.log('testing:', match[1]); |
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.
Most likely it's just to test the lexer as it was developed, I think we can remove it now.
frontend/i18n-scripts/po-to-i18n.js
Outdated
gettextToI18next(language, fs.readFileSync(fileName)).then(save(newFilePath)); | ||
gettextToI18next(language, fs.readFileSync(fileName)) | ||
.then(save(newFilePath)) | ||
.catch((e) => console.error(e, fileName)); |
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.
.catch((e) => console.error(e, fileName)); | |
.catch((e) => console.error(fileName, e)); |
}); | ||
fs.promises | ||
.writeFile(fileName, JSON.stringify(updatedFile, null, 2)) | ||
.catch((e) => console.error(e)); |
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.
.catch((e) => console.error(e)); | |
.catch((e) => console.error(fileName, e)); |
5a574a4
to
dd08bf8
Compare
@vojtechszocs thanks for the review. I've updated all the suggestions. |
adfc46b
to
f49bbef
Compare
updated lexer parser to use |
f49bbef
to
3012123
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: christianvogt, rebeccaalpert, vojtechszocs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/retest Please review the full test history for this PR and help us cut down flakes. |
Dynamic plugins contribute extensions through the
console-extensions.json
. To localize a string in json, the string must match the format/%.+%/
.eg.
This PR adds a custom lexer which parses
*.json
files and matches string values against the localization pattern.Added unit test for custom JSON lexer.
Update the
i18n-scripts/.eslintrc.js
rules to reuse those defined in the console eslint plugin.cc @rohitkrai03 @vojtechszocs @rebeccaalpert @spadgett
Before this change we would require a comment to pick up the localized string. Although there is no lexer currently for json files.
After this change, the lexer will pickup the string without the comment:
locale file:
helm-plugin.json