FIX: Fallback locale was not available for extra translations

Translations from fallback locales were not sent to the client
for admin_js and wizard_js.
This commit is contained in:
Gerhard Schlager
2019-05-23 21:23:31 +02:00
parent 0e24cb0f78
commit c1e9a70d59
8 changed files with 135 additions and 66 deletions

View File

@ -54,8 +54,15 @@ export default function(name, opts) {
andThen(() => {
return this.render(opts.template);
});
andThen(() => {
opts.test.call(this, assert);
try {
opts.test.call(this, assert);
} finally {
if (opts.afterEach) {
opts.afterEach.call(opts);
}
}
});
});
}

View File

@ -99,12 +99,68 @@ QUnit.test("translations", assert => {
});
QUnit.test("extra translations", assert => {
I18n.extras = [{ admin: { title: "Discourse Admin" } }];
I18n.locale = "pl_PL";
I18n.extras = {
en: {
admin: {
dashboard: {
title: "Dashboard",
backup_count: {
one: "%{count} backup",
other: "%{count} backups"
}
},
web_hooks: {
events: {
incoming: {
one: "There is a new event.",
other: "There are %{count} new events."
}
}
}
}
},
pl_PL: {
admin: {
dashboard: {
title: "Raporty"
},
web_hooks: {
events: {
incoming: {
one: "Istnieje nowe wydarzenie",
few: "Istnieją %{count} nowe wydarzenia.",
many: "Istnieje %{count} nowych wydarzeń.",
other: "Istnieje %{count} nowych wydarzeń."
}
}
}
}
}
};
I18n.pluralizationRules.pl_PL = function(n) {
if (n === 1) return "one";
if (n % 10 >= 2 && n % 10 <= 4) return "few";
if (n % 10 === 0) return "many";
return "other";
};
assert.equal(
I18n.t("admin.title"),
"Discourse Admin",
"it check extra translations when they exists"
I18n.t("admin.dashboard.title"),
"Raporty",
"it uses extra translations when they exists"
);
assert.equal(
I18n.t("admin.web_hooks.events.incoming", { count: 2 }),
"Istnieją 2 nowe wydarzenia.",
"it uses pluralized extra translation when it exists"
);
assert.equal(
I18n.t("admin.dashboard.backup_count", { count: 2 }),
"2 backups",
"it falls back to English and uses extra translations when they exists"
);
});

View File

@ -258,6 +258,8 @@ widgetTest("handlebars d-icon", {
});
widgetTest("handlebars i18n", {
_translations: I18n.translations,
template: `{{mount-widget widget="hbs-i18n-test" args=args}}`,
beforeEach() {
@ -268,15 +270,21 @@ widgetTest("handlebars i18n", {
<a href title={{i18n "hbs_test0"}}>test</a>
`
});
I18n.extras = [
{
hbs_test0: "evil",
hbs_test1: "trout"
I18n.translations = {
en: {
js: {
hbs_test0: "evil",
hbs_test1: "trout"
}
}
];
};
this.set("args", { key: "hbs_test1" });
},
afterEach() {
I18n.translations = this._translations;
},
test(assert) {
// comin up
assert.equal(find("span.string").text(), "evil");