-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Conversation
@@ -1,16 +1,238 @@ | |||
{ | |||
"lighthouse-core/audits/bootup-time.js | title": { |
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.
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", |
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.
😮
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: [ |
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 assert whatever the new value is?
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.
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} |
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.
these one
entries may have to all be =1
instead, but we can wait on that
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.
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); |
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.
these definitely seem like less good tests than before. Can we just assert against the default (en-US) results?
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.
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.
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.
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)
lighthouse-core/lib/i18n.js
Outdated
@@ -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 => { |
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.
the type definition seems to imply all the elements have id
. Is that not true?
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.
not sure, @paulirish did you find some without ids? :)
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.
@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'
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 you also update the dfn in typings/intl-messageformat-parser/index.d.ts
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.
done
@brendankenny what did you think of #5720, would that work for you? |
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.
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}; | |||
} |
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.
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)
this should be all of the audit messages necessary for performance
![image](https://user-images.githubusercontent.com/2301202/42970989-aeb83e4e-8b5f-11e8-8fcb-187a6f37210b.png)
what's left after this
Related Issues/PRs
blocked on #5655carried over from #5692