diff --git a/frontend/gettext.lua b/frontend/gettext.lua index 5fdef9306..e2359fcf0 100644 --- a/frontend/gettext.lua +++ b/frontend/gettext.lua @@ -188,6 +188,7 @@ function GetText_mt.__index.changeLang(new_lang) end local data = {} + local fuzzy = false local headers local what = nil while true do @@ -257,13 +258,18 @@ function GetText_mt.__index.changeLang(new_lang) -- string continuation s = line:match("^%s*\"(.*)\"%s*$") end - if what and s then + if what and s and not fuzzy then -- unescape \n or msgid won't match s = s:gsub("\\n", "\n") -- unescape " or msgid won't match s = s:gsub('\\"', '"') data[what] = (data[what] or "") .. s + else + -- Don't save this fuzzy string and unset fuzzy for the next one. + fuzzy = false end + elseif line:match("#, fuzzy") then + fuzzy = true end end end diff --git a/spec/unit/gettext_spec.lua b/spec/unit/gettext_spec.lua index 6d699383c..bec1d4eb6 100644 --- a/spec/unit/gettext_spec.lua +++ b/spec/unit/gettext_spec.lua @@ -97,6 +97,11 @@ msgstr[2] "Pagina's context 2 plural 2" msgstr[3] "" msgstr[4] "" msgstr[5] "" + +#: frontend/ui/data/css_tweaks.lua:50 +#, fuzzy +msgid "Fuzzy" +msgstr "Fuzzy translated" ]] describe("GetText module", function() @@ -210,6 +215,9 @@ describe("GetText module", function() describe("language with standard plurals", function() GetText.changeLang("nl_NL") + it("gettext should ignore fuzzy strings", function() + assert.is_equal("Fuzzy", GetText("Fuzzy")) + end) it("gettext should translate multiline string", function() assert.is_equal("\nbericht", GetText("\nmessage")) end) @@ -232,6 +240,9 @@ describe("GetText module", function() describe("language with simple plurals n > 2", function() GetText.changeLang("simple") + it("gettext should ignore fuzzy strings", function() + assert.is_equal("Fuzzy", GetText("Fuzzy")) + end) it("gettext should translate multiline string", function() assert.is_equal("\nbericht", GetText("\nmessage")) end) @@ -256,6 +267,9 @@ describe("GetText module", function() describe("language with no plurals", function() GetText.changeLang("none") + it("gettext should ignore fuzzy strings", function() + assert.is_equal("Fuzzy", GetText("Fuzzy")) + end) it("gettext should translate multiline string", function() assert.is_equal("\nbericht", GetText("\nmessage")) end) @@ -280,6 +294,9 @@ describe("GetText module", function() describe("language with complex plurals (Arabic)", function() GetText.changeLang("ar") + it("gettext should ignore fuzzy strings", function() + assert.is_equal("Fuzzy", GetText("Fuzzy")) + end) it("gettext should translate multiline string", function() assert.is_equal("\nbericht", GetText("\nmessage")) end) @@ -306,6 +323,9 @@ describe("GetText module", function() describe("language with complex plurals (Russian)", function() GetText.changeLang("ru") + it("gettext should ignore fuzzy strings", function() + assert.is_equal("Fuzzy", GetText("Fuzzy")) + end) it("gettext should translate multiline string", function() assert.is_equal("\nbericht", GetText("\nmessage")) end) @@ -332,6 +352,9 @@ describe("GetText module", function() -- to follow, so there we focus on algorithm correctness. describe("language with many plurals", function() GetText.changeLang("many") + it("gettext should ignore fuzzy strings", function() + assert.is_equal("Fuzzy", GetText("Fuzzy")) + end) it("gettext should translate multiline string", function() assert.is_equal("\nbericht", GetText("\nmessage")) end)