-
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
clients(devtools): only use locales that have locale files to download #13214
Conversation
@@ -85,6 +96,7 @@ if (typeof self !== 'undefined') { | |||
self.listenForStatus = listenForStatus; | |||
// @ts-expect-error | |||
self.registerLocaleData = registerLocaleData; | |||
// TODO: expose as lookupCanonicalLocale in LighthouseService.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.
not sure how much we care, though long term it's nice when the external thing is named the same as the internal thing for cross referencing
// TODO: lookupLocale may need to be split into two functions, one that canonicalizes | ||
// locales and one that looks up the best locale filename for a given locale. | ||
// e.g. `en-IE` is canonical, but uses `en-GB.json`. See TODO in locales.js |
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.
@paulirish depending on locale.js
keys for aliasing continues to feel a little gross, so it would feel good to take a swing at the aliasing thing soon. This is one possible split that might make sense. Also happy to remove this TODO, now that I'm looking at it it kind of reads like a PR comment :)
also we probably need a better name for |
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.
could you write a test that would break prior to this PR? something around just exposing the {}
locale obj to devtools?
aside from that, this sg
@@ -60,6 +60,17 @@ function listenForStatus(listenCallback) { | |||
log.events.addListener('status', listenCallback); | |||
} | |||
|
|||
/** | |||
* Does a locale lookup but limits the result to the *canonical* Lighthouse |
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 names feel a bit messed ATM. shared/localization/format.js has a "canonical locales" that is our "available" locales.
And then i18n.js has "canonical locales" as well, but that's the "correct" definition matching the result of Intl.getCanonicalLocales
the i18n object uses "supportedLocales" as well. i think this naming fits in a few places, since we basically have created a concept that's congruent with (a hypothetical) intl.messageformat.supportedLocalesOf()
i'm fine addressing this outside of this PR, but just flagging it now while its fresh.
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.
yeah, agree 100%
|
||
return minifyFileTransform(file); | ||
}, | ||
readFileTransform: minifyFileTransform, |
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.
i didnt spot this change in your description. this does mean all brfs'd items get minified yeah?
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.
i didnt spot this change in your description. this does mean all brfs'd items get minified yeah?
yeah, it's still running the minify transform over all the inlined files. The current readFileTransform
replaces the inlined file with {}
if it's one of the locale files, otherwise it runs minifyFileTransform
. Now we don't need to handle the individual locale files, so we can just always run minifyFileTransform
.
More or less reverting that part of #12921 since we can go back to just ignoring all of locales.js
The
that only fails if locales.js is set to |
ah right. yes okay then we good. :) |
follow up to the removed DevTools part of #13211
Before Lighthouse is run in DevTools, localization is figured out:
lookupLocale()
with the requested locale(s), get a supported Lighthouselocale
backlocale
isn't defaulten
/en-US
, fetch`third_party/lighthouse/locales/${locale}.json`
registerLocaleData()
In the subsequent Lighthouse run, messages are available for
locale
Step 1 relies on the list provided by
getAvailableLocales
(which is basicallyObject.keys(require('./locales.js'))
) to know what locales are available, so the DevTools bundle is reliant on our current bundling strategy of replacing each locale with a{}
(resulting in{'en-US': {}, 'en': {}, 'en-AU': {}, ...}
) instead of all oflocales.js
with a single{}
.This is what broke in (and was removed from) #13211:
Object.keys({})
is[]
, so there are no available locales,lookupLocale
always returns the defaulten
/en-US
, no other locale is ever fetched, and the report is always in english.But there's also a bug in the current implementation: with
locales.js
replaced with an object like{'en-US': {}, 'en': {}, 'en-AU': {}, ...}
,Object.keys(locales)
also picks up all the locale aliases, but then Step 2 will fail to fetch the alias because those don't have files to fetch (e.g.in
is a valid locale to return fromlookupLocale
, but there is nothird_party/lighthouse/locales/in.json
file to download, so it will fall back toen-US
instead of the much betterid
(which does have anid.json
to fetch)).In practice the bug may not be apparent because DevTools has its own dropdown list of locales, so there may only be a handful of possible selections that would result in a Lighthouse alias instead of a locale with a messages file.
This PR
lookupLocale
to provide a set of locales to (optionally) replace the defaultgetAvailableLocales
that the locale will be chosen from.devtools-entry.js
then uses this option to limit the choices to justgetCanonicalLocales()
, which is the set of locales that have actual locale files to downloadlocales.js
bundling patternlocales.js
with a{}
in the devtools bundle, as per our new bundling stylethe
lighthouse-i18n-run
chromium webtest is happy again, and can confirm withyarn open-devtools
that localization is working.