Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: src/js/i18n.js

Issue 2646593002: [intl] Fall back on an invalid default locale to "und" (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/i18n.js
diff --git a/src/js/i18n.js b/src/js/i18n.js
index 50ed5bcb8943cfeae6264e24ebdadf62e60a33f8..ba79f5b81062e313ee00a2dd502a1866674f0aae 100644
--- a/src/js/i18n.js
+++ b/src/js/i18n.js
@@ -153,6 +153,13 @@ var DEFAULT_ICU_LOCALE = UNDEFINED;
function GetDefaultICULocaleJS() {
if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) {
DEFAULT_ICU_LOCALE = %GetDefaultICULocale();
+ // Check that this is a valid default, otherwise fall back to "en"
+ for (let service in AVAILABLE_LOCALES) {
+ if (IS_UNDEFINED(getAvailableLocalesOf(service)[DEFAULT_ICU_LOCALE])) {
+ DEFAULT_ICU_LOCALE = "en";
jungshik at Google 2017/01/19 19:16:22 Hmm... I'm not sure of falling back to 'en'. How a
Dan Ehrenberg 2017/02/10 08:54:28 Done.
+ break;
+ }
+ }
}
return DEFAULT_ICU_LOCALE;
}
@@ -298,19 +305,16 @@ function supportedLocalesOf(service, locales, options) {
var requestedLocales = initializeLocaleList(locales);
- // Cache these, they don't ever change per service.
- if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) {
- AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service);
- }
+ var availableLocales = getAvailableLocalesOf(service);
// Use either best fit or lookup algorithm to match locales.
if (matcher === 'best fit') {
return initializeLocaleList(bestFitSupportedLocalesOf(
- requestedLocales, AVAILABLE_LOCALES[service]));
+ requestedLocales, availableLocales));
}
return initializeLocaleList(lookupSupportedLocalesOf(
- requestedLocales, AVAILABLE_LOCALES[service]));
+ requestedLocales, availableLocales));
}
@@ -437,17 +441,14 @@ function lookupMatcher(service, requestedLocales) {
throw %make_error(kWrongServiceType, service);
}
- // Cache these, they don't ever change per service.
- if (IS_UNDEFINED(AVAILABLE_LOCALES[service])) {
- AVAILABLE_LOCALES[service] = getAvailableLocalesOf(service);
- }
+ var availableLocales = getAvailableLocalesOf(service);
for (var i = 0; i < requestedLocales.length; ++i) {
// Remove all extensions.
var locale = %RegExpInternalReplace(
GetAnyExtensionRE(), requestedLocales[i], '');
do {
- if (!IS_UNDEFINED(AVAILABLE_LOCALES[service][locale])) {
+ if (!IS_UNDEFINED(availableLocales[locale])) {
// Return the resolved locale and extension.
var extensionMatch = %regexp_internal_match(
GetUnicodeExtensionRE(), requestedLocales[i]);
@@ -658,6 +659,11 @@ function getOptimalLanguageTag(original, resolved) {
* that is supported. This is required by the spec.
*/
function getAvailableLocalesOf(service) {
+ // Cache these, they don't ever change per service.
+ if (!IS_UNDEFINED(AVAILABLE_LOCALES[service])) {
+ return AVAILABLE_LOCALES[service];
+ }
+
var available = %AvailableLocalesOf(service);
for (var i in available) {
@@ -672,6 +678,8 @@ function getAvailableLocalesOf(service) {
}
}
+ AVAILABLE_LOCALES[service] = available;
+
return available;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698