mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
[i18n] GetText: ignore fuzzy strings (#5807)
Strings are prefilled by msgmerge with closely matching ones to reduce the amount of labor required by the translator. Often the string requires only minor adjustment, making the process faster, and when the string isn't a good match it's no big deal. However, these so-called fuzzy strings shouldn't be treated as if they were actually translated. Fixes the effect seen in <https://github.com/koreader/koreader/issues/5806>.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user