Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add count to missing translation strings (#15509)

Jarek Radosz71cf6839ab10
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js b/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
index be4699d6846..94d05dd0cb2 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
@@ -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 }),
diff --git a/app/assets/javascripts/locales/i18n.js b/app/assets/javascripts/locales/i18n.js
index 142e1bc6697..bde0d1a7bb8 100644
--- a/app/assets/javascripts/locales/i18n.js
+++ b/app/assets/javascripts/locales/i18n.js
@@ -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 + "]";
};