mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1588199 - Load local fluent file for ASRouter as fallback r=Pike,Mardak
This changes the either-or semantics to one-after between the local and remote fluent files for ASRouter. Differential Revision: https://phabricator.services.mozilla.com/D49068 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
5e0abce31f
commit
f0ac756360
@ -136,16 +136,6 @@ class PageAction {
|
||||
* * it was told to use the local Fluent file
|
||||
*/
|
||||
_createDOML10n() {
|
||||
const ftlResourceIDs = [
|
||||
"browser/newtab/asrouter.ftl",
|
||||
"browser/branding/brandings.ftl",
|
||||
"browser/branding/sync-brand.ftl",
|
||||
"branding/brand.ftl",
|
||||
];
|
||||
if (!Services.prefs.getBoolPref(USE_REMOTE_L10N_PREF, true)) {
|
||||
return new DOMLocalization(ftlResourceIDs);
|
||||
}
|
||||
|
||||
async function* generateBundles(resourceIds) {
|
||||
const appLocale = Services.locale.appLocaleAsBCP47;
|
||||
const appLocales = Services.locale.appLocalesAsBCP47;
|
||||
@ -157,25 +147,32 @@ class PageAction {
|
||||
// In the case that the Fluent file has not been downloaded from Remote Settings,
|
||||
// `fetchFile` will return `false` and fall back to the packaged Fluent file.
|
||||
const resource = await fs.fetchFile(appLocale, "asrouter.ftl");
|
||||
if (resource) {
|
||||
// Skip the local `asrouter.ftl` (i.e. the first resource) to favor the remote one.
|
||||
// Other resources such as `branding.ftl`, `sync-brand.ftl`, and `branding/brand.ftl`
|
||||
// still need to be packed into this bundle because, otherwise, we can't reference
|
||||
// them across different Fluent bundles.
|
||||
for await (let bundle of L10nRegistry.generateBundles(
|
||||
[appLocale],
|
||||
resourceIds.slice(1)
|
||||
)) {
|
||||
// Override the old string ID if any as it's the last resource.
|
||||
bundle.addResource(resource, true);
|
||||
yield bundle;
|
||||
for await (let bundle of L10nRegistry.generateBundles(
|
||||
appLocales.slice(0, 1),
|
||||
resourceIds
|
||||
)) {
|
||||
// Override built-in messages with the resource loaded from remote settings for
|
||||
// the app locale, i.e. the first item of `appLocales`.
|
||||
if (resource) {
|
||||
bundle.addResource(resource, { allowOverrides: true });
|
||||
}
|
||||
} else {
|
||||
yield* L10nRegistry.generateBundles(appLocales, resourceIds);
|
||||
yield bundle;
|
||||
}
|
||||
// Now generating bundles for the rest of locales of `appLocales`.
|
||||
yield* L10nRegistry.generateBundles(appLocales.slice(1), resourceIds);
|
||||
}
|
||||
|
||||
return new DOMLocalization(ftlResourceIDs, generateBundles);
|
||||
return new DOMLocalization(
|
||||
[
|
||||
"browser/newtab/asrouter.ftl",
|
||||
"browser/branding/brandings.ftl",
|
||||
"browser/branding/sync-brand.ftl",
|
||||
"branding/brand.ftl",
|
||||
],
|
||||
Services.prefs.getBoolPref(USE_REMOTE_L10N_PREF, true)
|
||||
? generateBundles
|
||||
: undefined
|
||||
);
|
||||
}
|
||||
|
||||
reloadL10n() {
|
||||
|
@ -770,18 +770,22 @@ describe("CFRPageActions", () => {
|
||||
"browser/branding/sync-brand.ftl",
|
||||
"branding/brand.ftl",
|
||||
]);
|
||||
assert.isFunction(args[1]);
|
||||
});
|
||||
it("should load the local Fluent file if USE_REMOTE_L10N_PREF is false", () => {
|
||||
sandbox.stub(global.Services.prefs, "getBoolPref").returns(false);
|
||||
pageAction._createDOML10n();
|
||||
|
||||
assert.calledOnce(domL10nStub);
|
||||
assert.calledWith(domL10nStub, [
|
||||
const { args } = domL10nStub.firstCall;
|
||||
// The first arg is the resource array, and the second one should be null.
|
||||
assert.equal(args.length, 2);
|
||||
assert.deepEqual(args[0], [
|
||||
"browser/newtab/asrouter.ftl",
|
||||
"browser/branding/brandings.ftl",
|
||||
"browser/branding/sync-brand.ftl",
|
||||
"branding/brand.ftl",
|
||||
]);
|
||||
assert.isUndefined(args[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user