mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
DEV: Add count to missing translation strings (#15509)
…for easier debugging of i18n issues.
This commit is contained in:
parent
25a0fae9a4
commit
71cf6839ab
2 changed files with 33 additions and 3 deletions
|
@ -122,7 +122,7 @@ module("Unit | Utility | i18n", function (hooks) {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
I18n.t("hello.world"),
|
I18n.t("hello.world"),
|
||||||
"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");
|
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");
|
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) {
|
test("fallback", function (assert) {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
I18n.t("days", { count: 1 }),
|
I18n.t("days", { count: 1 }),
|
||||||
|
|
|
@ -168,7 +168,7 @@ I18n.translate = function(scope, options) {
|
||||||
try {
|
try {
|
||||||
return this.interpolate(translation, options);
|
return this.interpolate(translation, options);
|
||||||
} catch (error) {
|
} 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]);
|
return this.missingTranslation(scope, keys[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
I18n.missingTranslation = function(scope, key) {
|
I18n.missingTranslation = function(scope, key, options) {
|
||||||
var message = "[" + this.currentLocale() + this.SEPARATOR + scope;
|
var message = "[" + this.currentLocale() + this.SEPARATOR + scope;
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
message += this.SEPARATOR + key;
|
message += this.SEPARATOR + key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options && options.hasOwnProperty("count")) {
|
||||||
|
message += " count=" + JSON.stringify(options.count);
|
||||||
|
}
|
||||||
|
|
||||||
return message + "]";
|
return message + "]";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue