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

core(i18n): support descriptions #5718

Merged
merged 8 commits into from
Jul 26, 2018
Merged

core(i18n): support descriptions #5718

merged 8 commits into from
Jul 26, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Jul 24, 2018

Adds support for string descriptions and defaulting all failureTitles to one for example

Related Issues/PRs
blocked on #5716

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

This is totally rad. I like it.

const content = fs.readFileSync(fullPath, 'utf8');
if (!UISTRINGS_REGEX.test(content)) continue;
const exportVars = require(fullPath);
if (!exportVars.UIStrings) throw new Error('UIStrings not exported');
Copy link
Member

Choose a reason for hiding this comment

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

UIStrings defined but not exported

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done!


// @ts-ignore regex just matched
const justUIStrings = content.match(UISTRINGS_REGEX)[0];
// just parse the UIStrings substring to avoid ES version issues, save time, etc
Copy link
Member

Choose a reason for hiding this comment

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

👍 i like this approach.

@@ -10,8 +10,17 @@

const fs = require('fs');
const path = require('path');
// @ts-ignore - TODO: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/25410
Copy link
Member

Choose a reason for hiding this comment

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

looks like that landed?
DefinitelyTyped/DefinitelyTyped#25410

@patrickhulce patrickhulce changed the base branch from i18n_all_perf_strings to master July 25, 2018 22:11
@patrickhulce
Copy link
Collaborator Author

@brendankenny you gellin'?

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

general approach looks good!

failureTitle: 'Shown to users as the title of the audit when it is in a failing state.',
};

// @ts-ignore - waiting for esprima types, see above TODO
Copy link
Member

Choose a reason for hiding this comment

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

no more ts-ignore? or annoying to type even with types

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated the comment, @types/esprima doesn't actually come with typedefs for any of this

@@ -23,16 +23,13 @@
"build-viewer": "cd ./lighthouse-viewer && yarn build",
"clean": "rimraf *.report.html *.report.dom.html *.report.json *.screenshots.html *.screenshots.json *.devtoolslog.json *.trace.json || true",
"lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .",

Copy link
Member

Choose a reason for hiding this comment

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

revert these or do we just want to give up on them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm personally for giving up, but I can revert if we're still trying to keep the dream alive

Copy link
Member

Choose a reason for hiding this comment

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

@@ -119,7 +115,7 @@
"chrome-launcher": "^0.10.2",
"configstore": "^3.1.1",
"devtools-timeline-model": "1.1.6",
"esprima": "^4.0.0",
"esprima": "^4.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

do we want to fix on a specific version since it's a (possibly) finicky extraction task?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

eh 🤷‍♀️ we've got yarn.lock for the script and the other usage isn't that sensitive

Copy link
Member

Choose a reason for hiding this comment

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

we've got yarn.lock for the script

ha, well I feel like that's a reason to just drop the ^ since we don't honor it anyways, but

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I disagree :)

This approach makes sure our usage is locked in for our script but when others install lighthouse we accept any version of esprima 4 when it doesn't matter as much in the audit

// @ts-ignore regex just matched
const justUIStrings = 'const ' + content.match(UISTRINGS_REGEX)[0];
// just parse the UIStrings substring to avoid ES version issues, save time, etc
// @ts-ignore - esprima's type definition is supremely lacking
Copy link
Member

Choose a reason for hiding this comment

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

yeah, it's pretty terrible as I recall

const content = fs.readFileSync(fullPath, 'utf8');
if (!UISTRINGS_REGEX.test(content)) continue;
const exportVars = require(fullPath);
if (!exportVars.UIStrings) throw new Error('UIStrings defined but not exported');
Copy link
Member

Choose a reason for hiding this comment

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

we should probably also do the opposite test too, UIStrings exported but failing the regex just in case one of them ends up weird in one file or something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

*/
function writeStringsToLocaleFormat(locale, strings) {
const fullPath = path.join(LH_ROOT, `lighthouse-core/lib/locales/${locale}.json`);
const output = {};
for (const [key, message] of Object.entries(strings)) {
output[key] = {message};
for (const [key, object] of Object.entries(strings)) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: above defn is used...might be better than object here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


// @ts-ignore - waiting for esprima types, see above TODO
function computeDescription(ast, property, startRange) {
const endRange = property.range[0];
Copy link
Member

Choose a reason for hiding this comment

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

do we want to prepend [ICU Syntax]​ here if it is?

Copy link
Collaborator Author

@patrickhulce patrickhulce Jul 26, 2018

Choose a reason for hiding this comment

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

@paulirish was against that since it only applies to ones that have the template and there are only ~5, I was persuaded as well :)

const UISTRINGS_REGEX = /UIStrings = (.|\s)*?\};\n/gim;

/**
* @typedef ICUMessage
Copy link
Member

Choose a reason for hiding this comment

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

ICUMessage.message is a little unfortunate (e.g. destructuring like const [key, msg] of Object.entries(strings) below would be weird because then you'd need to say msg.message) , but I don't have anything better. ICUMessageDefn :) Not sure if there are any other terms of art

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

*Defn it is!

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -119,7 +115,7 @@
"chrome-launcher": "^0.10.2",
"configstore": "^3.1.1",
"devtools-timeline-model": "1.1.6",
"esprima": "^4.0.0",
"esprima": "^4.0.1",
Copy link
Member

Choose a reason for hiding this comment

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

we've got yarn.lock for the script

ha, well I feel like that's a reason to just drop the ^ since we don't honor it anyways, but

@@ -23,16 +23,13 @@
"build-viewer": "cd ./lighthouse-viewer && yarn build",
"clean": "rimraf *.report.html *.report.dom.html *.report.json *.screenshots.html *.screenshots.json *.devtoolslog.json *.trace.json || true",
"lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .",

Copy link
Member

Choose a reason for hiding this comment

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

@@ -3,7 +3,8 @@
"message": "JavaScript boot-up time"
},
"lighthouse-core/audits/bootup-time.js | failureTitle": {
"message": "JavaScript boot-up time is too high"
"message": "JavaScript boot-up time is too high",
Copy link
Member

Choose a reason for hiding this comment

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

this file might need to be regenerated now

@paulirish paulirish merged commit 5633819 into master Jul 26, 2018
@brendankenny brendankenny deleted the i18n_descriptions branch July 26, 2018 23:02
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.

3 participants