-
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
i18n: add better support for the default locale in bundles #13211
Conversation
@@ -283,6 +283,7 @@ function resolveSettings(settingsJson = {}, overrides = undefined) { | |||
// If a locale is requested in flags or settings, use it. A typical CLI run will not have one, | |||
// however `lookupLocale` will always determine which of our supported locales to use (falling | |||
// back if necessary). | |||
// TODO: could do more work to sniff out the user's locale |
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.
longtime TODO in i18n.js
but seemed better here where the locale is actually chosen
* is to replace the default export of this file with `{}` so that no locale messages | ||
* are included. Strings will work normally through the IcuMessage.formattedDefault | ||
* fallback, and locale messages can be added on demand (e.g. dynamically fetched) | ||
* through `format.registerLocaleData()`. |
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 who will ever look in here, but worth documenting somewhere :)
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!
#9520 (comment) is a previous discussion about it. the linked blog post sez:
That does line up with the plan here. Anyway, for the moment, english inheritance is kinda broken in CLDR. so.. there's no "right" answer for our default being either 'en' or 'en-US'. So it's fine going with whatever's more straightforward. :) |
Ok, the devtools error is real, so I'm going to back out the |
d76efaf
to
aa63612
Compare
Recently we've been circling around a few different ways to strip the locale data out of bundles, each slightly different, so it seemed like a good time to settle on one (this also makes the brfs replacement easier).
This PR sets us up so we can always replace
locales.js
with{}
. Everything works without reaching too deep and/or custom shimming. There are no messages available for localization unless the client using the bundle brings them, either viaregisterLocaleData
when running lighthouse-core or viarendererFormattedStrings
equivalents in the report. Viewer locale swapping already works like this and it's working well :)changes in format.js/i18n.js:
{}
for our locales because the default fallbacks (provided by each file'sUIStrings
) are always available, however there are a few places whereLOCALE_MESSAGES[requestedLocale]
is checked for truthiness, which would fail with this approach. Added a new condition where if the default locale is being requested, the caller now gets a return value that allows the default fallback behavior to happen.format.js
now defines theDEFAULT_LOCALE
, which is nowen-US
, noten
. I don't remember the discussion with how we landed onen
for the theoretical default, but we actually default toen-US
so I'm treating that as the thing to use for now. @paulirish if you remember how we were supposed to resolve thischanges in build/build-bundle.js
DevTools currently uses a slightly different transform, where each locale in locales.js is replaced with an empty object (nevermind for the moment: #13211 (comment){'ar': {}, 'ar-XB': {}, 'bg': {}, ...}
). To verify the new approach, we go back to the approach before #12921 and shim justlocale.js
with a{}
.