зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1373061 - Fallback on en-US in sdk/l10n.get. r=Pike
Users of getPreferedLocales method expect to always have `en-US` as a last resort. This patch brings back the behavior which regressed with the landing of bug 1346616. MozReview-Commit-ID: 8bgm7PJnSRJ --HG-- extra : rebase_source : c63ba6e4508117a6d4bd9d2a18a2c8665dd52bbe
This commit is contained in:
Родитель
509fba7d22
Коммит
86a8ec763b
|
@ -12,7 +12,15 @@ const { Cu, Cc, Ci } = require("chrome");
|
|||
const { Services } = Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function getPreferedLocales(caseSensitve) {
|
||||
return Services.locale.getRequestedLocales();
|
||||
const locales = Services.locale.getRequestedLocales();
|
||||
|
||||
// This API expects to always append en-US fallback, so for compatibility
|
||||
// reasons, we're going to inject it here.
|
||||
// See bug 1373061 for details.
|
||||
if (!locales.includes('en-US')) {
|
||||
locales.push('en-US');
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
exports.getPreferedLocales = getPreferedLocales;
|
||||
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const { findClosestLocale } = require("sdk/l10n/locale");
|
||||
const { Cu, Cc, Ci } = require("chrome");
|
||||
const { Services } = Cu.import('resource://gre/modules/Services.jsm');
|
||||
const { findClosestLocale,
|
||||
getPreferedLocales } = require("sdk/l10n/locale");
|
||||
|
||||
exports.testFindClosestLocale = function(assert) {
|
||||
// Second param of findClosestLocale (aMatchLocales) have to be in lowercase
|
||||
|
@ -44,4 +47,14 @@ exports.testFindClosestLocale = function(assert) {
|
|||
"ja", "We accept locale with 1 part from locale with 3 parts");
|
||||
};
|
||||
|
||||
exports.testGetPreferedLocales = function(assert) {
|
||||
let currentLocales = Services.locale.getRequestedLocales();
|
||||
|
||||
Services.locale.setRequestedLocales(['pl']);
|
||||
|
||||
assert.equal(getPreferedLocales().includes('en-US'), true, "en-US should always be in the list");
|
||||
|
||||
Services.locale.setRequestedLocales(currentLocales);
|
||||
};
|
||||
|
||||
require('sdk/test').run(exports);
|
||||
|
|
Загрузка…
Ссылка в новой задаче