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): extract performance strings to UIStrings #5716

Merged
merged 12 commits into from
Jul 25, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Jul 24, 2018

this should be all of the audit messages necessary for performance
image

what's left after this

Related Issues/PRs
blocked on #5655
carried over from #5692

@patrickhulce patrickhulce changed the title I18n all perf strings core(i18n): extract performance strings to UIStrings Jul 24, 2018
@@ -1,16 +1,238 @@
{
"lighthouse-core/audits/bootup-time.js | title": {
Copy link
Member

Choose a reason for hiding this comment

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

we'll probably want to stop generating this file when we get our first translation dump (this locale is automatically generated for us)

"%10d ms",
1548.5690000000002
],
"displayValue": "NaN ms",
Copy link
Member

Choose a reason for hiding this comment

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

😮

how about

diff --git a/lighthouse-core/lib/i18n.js b/lighthouse-core/lib/i18n.js
index 0c4d6d24..2776af87 100644
--- a/lighthouse-core/lib/i18n.js
+++ b/lighthouse-core/lib/i18n.js
@@ -65,6 +65,14 @@ function _preprocessMessageValues(icuMessage, values) {
 
   const clonedValues = JSON.parse(JSON.stringify(values));
   const parsed = MessageParser.parse(icuMessage);
+
+  // Throw an error if a message's value isn't provided
+  parsed.elements.map(el => el.id).filter(Boolean).forEach(valueId => {
+    if ((valueId in values) === false) {
+      throw new Error('ICU Message contains a value reference that wasn\'t provided');
+    }
+  });
+

@@ -94,10 +94,6 @@ module.exports = [
},
},
'uses-responsive-images': {
displayValue: [
Copy link
Member

Choose a reason for hiding this comment

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

can we assert whatever the new value is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ya, my comment below applies here too though for rationale :)

'A long cache lifetime can speed up repeat visits to your page. ' +
'[Learn more](https://developers.google.com/web/tools/lighthouse/audits/cache-policy).',
displayValue: `{itemCount, plural,
one {1 resource found}
Copy link
Member

Choose a reason for hiding this comment

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

these one entries may have to all be =1 instead, but we can wait on that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

might as well do now, fixed 👍

@@ -176,7 +176,7 @@ describe('Byte efficiency base audit', () => {
],
}, graph, simulator);

assert.ok(result.displayValue.includes(2), 'contains correct KB');
assert.ok(result.displayValue);
Copy link
Member

Choose a reason for hiding this comment

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

these definitely seem like less good tests than before. Can we just assert against the default (en-US) results?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the display values coming out of audits now are just temporary string IDs that reference something stored in i18n, so they don't have anything to do with the audit itself.

I'm somewhat against having so many layers asserting displayValue. It's been a large source of churn that hasn't really caught much. The end result in the LHR is really the only thing we care about which is OKishly captured by golden LHR.

Copy link
Member

Choose a reason for hiding this comment

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

the display values coming out of audits now are just temporary string IDs that reference something stored in i18n, so they don't have anything to do with the audit itself

good point. We could do i18n.replaceIcuMessageInstanceIds(result, 'en-US'), then test result.displayValue here, I guess.

I'm somewhat against having so many layers asserting displayValue. It's been a large source of churn that hasn't really caught much. The end result in the LHR is really the only thing we care about which is OKishly captured by golden LHR.

I mean, that's pretty much an argument against all unit tests. 90+% of the time none of them will fail, until that one time we drop a closing } to a pluralization argument and the display value just becomes a literal string (or whatever).

Generating a displayValue is pretty much all several of our audits are doing, the rest is in gatherers or computed artifacts. It doesn't seem unreasonable to assert their actual root source is generating them correctly.

(and dbw_tester.html, while a workhorse, can't cover all the cases we'd care about)

@@ -58,6 +65,13 @@ function _preprocessMessageValues(icuMessage, values) {

const clonedValues = JSON.parse(JSON.stringify(values));
const parsed = MessageParser.parse(icuMessage);
// Throw an error if a message's value isn't provided
parsed.elements.map(el => el.id).filter(Boolean).forEach(valueId => {
Copy link
Member

Choose a reason for hiding this comment

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

the type definition seems to imply all the elements have id. Is that not true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure, @paulirish did you find some without ids? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@brendankenny correct the types are wrong, all things with a format have id but the strings in between don't, we'll switch to filter on type === 'ArgumentElement'

Copy link
Member

Choose a reason for hiding this comment

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

can you also update the dfn in typings/intl-messageformat-parser/index.d.ts

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

@patrickhulce
Copy link
Collaborator Author

@brendankenny what did you think of #5720, would that work for you?

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!

amazing work getting all of these extracted

@@ -1,7 +1,7 @@
declare module 'intl-messageformat-parser' {
interface Element {
type: 'messageTextElement'|'argumentElement';
id: string
id?: string
value?: string
format?: null | {type: string; style?: string};
}
Copy link
Member

Choose a reason for hiding this comment

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

if format and id are always defined if the other is, it may make sense to make a discriminated union out of this, but fine for now (won't help with the .filter()s anyway)

@brendankenny brendankenny merged commit e99673b into master Jul 25, 2018
@paulirish paulirish deleted the i18n_all_perf_strings branch July 26, 2018 00:09
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