DEV: Add count to missing translation strings (#15509)
…for easier debugging of i18n issues.
This commit is contained in:
parent
25a0fae9a4
commit
71cf6839ab
|
@ -122,7 +122,7 @@ module("Unit | Utility | i18n", function (hooks) {
|
|||
assert.strictEqual(
|
||||
I18n.t("hello.world"),
|
||||
"Hello World!",
|
||||
"doesn't break if a key is overriden in a locale"
|
||||
"doesn't break if a key is overridden in a locale"
|
||||
);
|
||||
assert.strictEqual(I18n.t("hello.universe"), "", "allows empty strings");
|
||||
});
|
||||
|
@ -215,6 +215,30 @@ module("Unit | Utility | i18n", function (hooks) {
|
|||
assert.strictEqual(I18n.t("word_count", { count: 100 }), "100 words");
|
||||
});
|
||||
|
||||
test("adds the count to the missing translation strings", function (assert) {
|
||||
assert.strictEqual(
|
||||
I18n.t("invalid_i18n_string", { count: 1 }),
|
||||
`[fr.invalid_i18n_string count=1]`
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
I18n.t("character_count", { count: "0" }),
|
||||
`[fr.character_count count="0"]`
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
I18n.t("character_count", { count: null }),
|
||||
`[fr.character_count count=null]`
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
I18n.t("character_count", { count: undefined }),
|
||||
`[fr.character_count count=undefined]`
|
||||
);
|
||||
|
||||
assert.strictEqual(I18n.t("character_count"), "[fr.character_count]");
|
||||
});
|
||||
|
||||
test("fallback", function (assert) {
|
||||
assert.strictEqual(
|
||||
I18n.t("days", { count: 1 }),
|
||||
|
|
|
@ -168,7 +168,7 @@ I18n.translate = function(scope, options) {
|
|||
try {
|
||||
return this.interpolate(translation, options);
|
||||
} catch (error) {
|
||||
return this.missingTranslation(scope);
|
||||
return this.missingTranslation(scope, null, options);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -297,11 +297,17 @@ I18n.pluralize = function(translation, scope, options) {
|
|||
return this.missingTranslation(scope, keys[0]);
|
||||
};
|
||||
|
||||
I18n.missingTranslation = function(scope, key) {
|
||||
I18n.missingTranslation = function(scope, key, options) {
|
||||
var message = "[" + this.currentLocale() + this.SEPARATOR + scope;
|
||||
|
||||
if (key) {
|
||||
message += this.SEPARATOR + key;
|
||||
}
|
||||
|
||||
if (options && options.hasOwnProperty("count")) {
|
||||
message += " count=" + JSON.stringify(options.count);
|
||||
}
|
||||
|
||||
return message + "]";
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue