Skip to content

Conversation

@brendankenny
Copy link
Contributor

@brendankenny brendankenny commented Aug 20, 2019

we have a check that all arguments in an ICU message have values passed into our i18n functions; this PR adds a check that all the values passed in have a place to be used in the ICU message. This is useful when strings change since we have no type checking that our localized strings match the values being passed in for replacement.

I was originally going to include this in #9570, but ran into a ton of errors in our unit tests. Turns out this is just because LHError always includes errorCode in the replacement values so you don't have to write 'NO_FCP' three times just to get a NO_FCP error. I added a comment to remind the next person about errorCode.

This condition currently only happens in one place (the change in #9486 removing itemCount), but removing itemCount reveals a flaw in our system: if the ICU arguments in a string aren't provided in values, we throw an error (and if we don't throw one, intl-messageformat does). This is an issue when the other locale files have strings with different ICU arguments than the en-US one does (as is currently case for third-party-summary.js | displayValue).

This is a pretty fundamental issue so going to fix that before landing this :)

const expectedPathId = 'lighthouse-core/test/lib/i18n/fake-file-number-2.js | aString';
expect(icuMessagePaths).toEqual({
[templateID]: [{path: 'audits[fake-audit].title', values: {x: 1}}]});
[expectedPathId]: [{path: 'audits[fake-audit].title', values: {x: 1}}]});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dangers of singletons :) this test was implicitly relying on the test above having called createMessageInstanceIdFn

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM

sirNotAppearingInThisString: 66,
});
expect(_ => i18n.getFormatted(helloStr, 'en-US'))
// eslint-disable-next-line max-len
Copy link
Collaborator

Choose a reason for hiding this comment

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

apparently we've decided there's disagreement on this point so we should never use disable-next-line max-len again :P

@exterkamp I'm gonna love this convo next week where I can learn how splitting is possibly better 😆

@patrickhulce
Copy link
Collaborator

some unit tests are still unhappy about spanish locale swap though

@brendankenny
Copy link
Contributor Author

ok, with #9598 in, the tests for this should now all pass 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants