Commit 5228af67 authored by Daniel Ehrenberg's avatar Daniel Ehrenberg Committed by Commit Bot

[intl] Use a service-dependent default locale

Different Intl features (DateTimeFormat, NumberFormat, etc) have
different lists of locales supported. Previously, the default locale
was set to "und", as opposed to what was detected from the surrounding
system, if any of these features was missing data. With this patch,
only that feature is set to "und". In this way, the data quality should
be just as good as if there were no fallback logic, but at the same time,
resolvedOptions().locale should show the locale actually in effect.

R=adamk,jshin
BUG=v8:6288

Change-Id: I62b083a1dde2465cb1541cb18ecc7e59f9097bc0
Reviewed-on: https://chromium-review.googlesource.com/492886
Commit-Queue: Daniel Ehrenberg <littledan@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45109}
parent ae5ae1cc
...@@ -146,18 +146,18 @@ var AVAILABLE_LOCALES = { ...@@ -146,18 +146,18 @@ var AVAILABLE_LOCALES = {
*/ */
var DEFAULT_ICU_LOCALE = UNDEFINED; var DEFAULT_ICU_LOCALE = UNDEFINED;
function GetDefaultICULocaleJS() { function GetDefaultICULocaleJS(service) {
if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) { if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) {
DEFAULT_ICU_LOCALE = %GetDefaultICULocale(); DEFAULT_ICU_LOCALE = %GetDefaultICULocale();
// Check that this is a valid default, otherwise fall back to "und"
for (let service in AVAILABLE_LOCALES) {
if (IS_UNDEFINED(getAvailableLocalesOf(service)[DEFAULT_ICU_LOCALE])) {
DEFAULT_ICU_LOCALE = "und";
break;
}
}
} }
return DEFAULT_ICU_LOCALE; // Check that this is a valid default for this service,
// otherwise fall back to "und"
// TODO(littledan,jshin): AvailableLocalesOf sometimes excludes locales
// which don't require tailoring, but work fine with root data. Look into
// exposing this fact in ICU or the way Chrome bundles data.
return (IS_UNDEFINED(service) ||
HAS_OWN_PROPERTY(getAvailableLocalesOf(service), DEFAULT_ICU_LOCALE))
? DEFAULT_ICU_LOCALE : "und";
} }
/** /**
...@@ -449,7 +449,7 @@ function lookupMatcher(service, requestedLocales) { ...@@ -449,7 +449,7 @@ function lookupMatcher(service, requestedLocales) {
var extensionMatch = %regexp_internal_match( var extensionMatch = %regexp_internal_match(
GetUnicodeExtensionRE(), requestedLocales[i]); GetUnicodeExtensionRE(), requestedLocales[i]);
var extension = IS_NULL(extensionMatch) ? '' : extensionMatch[0]; var extension = IS_NULL(extensionMatch) ? '' : extensionMatch[0];
return {'locale': locale, 'extension': extension, 'position': i}; return {locale: locale, extension: extension, position: i};
} }
// Truncate locale if possible. // Truncate locale if possible.
var pos = %StringLastIndexOf(locale, '-'); var pos = %StringLastIndexOf(locale, '-');
...@@ -461,7 +461,11 @@ function lookupMatcher(service, requestedLocales) { ...@@ -461,7 +461,11 @@ function lookupMatcher(service, requestedLocales) {
} }
// Didn't find a match, return default. // Didn't find a match, return default.
return {'locale': GetDefaultICULocaleJS(), 'extension': '', 'position': -1}; return {
locale: GetDefaultICULocaleJS(service),
extension: '',
position: -1
};
} }
......
...@@ -546,6 +546,7 @@ ...@@ -546,6 +546,7 @@
# Setting the timezone and locale with environment variables unavailable # Setting the timezone and locale with environment variables unavailable
'icu-date-to-string': [SKIP], 'icu-date-to-string': [SKIP],
'icu-date-lord-howe': [SKIP], 'icu-date-lord-howe': [SKIP],
'regress/regress-6288': [SKIP],
}], # 'system == windows' }], # 'system == windows'
############################################################################## ##############################################################################
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Environment Variables: LC_ALL=pt-BR.UTF8
// The data files packaged with d8 currently have Brazillian Portugese
// DateTimeFormat but not Collation
if (this.Intl) {
assertEquals('und', Intl.Collator().resolvedOptions().locale);
assertEquals('pt-BR', Intl.DateTimeFormat().resolvedOptions().locale);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment