FIX: allow for empty translated strings

This commit is contained in:
Régis Hanol 2017-03-01 11:30:44 +01:00
parent e27b1b98d1
commit b20b568039
2 changed files with 10 additions and 2 deletions

View File

@ -73,7 +73,13 @@ I18n.lookup = function(scope, options) {
messages = messages[currentScope]; messages = messages[currentScope];
} }
messages = messages || checkExtras(origScope, this.SEPARATOR, this.extras) || options.defaultValue; if (messages === undefined) {
messages = checkExtras(origScope, this.SEPARATOR, this.extras);
}
if (messages === undefined) {
messages = options.defaultValue;
}
return messages; return messages;
}; };

View File

@ -27,7 +27,8 @@ module("lib:i18n", {
"en": { "en": {
"js": { "js": {
"hello": { "hello": {
"world": "Hello World!" "world": "Hello World!",
"universe": ""
}, },
"topic": { "topic": {
"reply": { "reply": {
@ -68,6 +69,7 @@ test("translations", function() {
equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist"); equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist");
equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations"); equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations");
equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale"); equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale");
equal(I18n.t("hello.universe"), "", "allows empty strings");
}); });
test("extra translations", function() { test("extra translations", function() {