[fix] gettext: don't replace backslash characters (#8511)

Everything in string.gsub() is replaced, not only the matching group. By using two groups, we can correctly return the full matched string when none of the special conditions apply.

Fixes <https://github.com/koreader/koreader/issues/8486>.
reviewable/pr8513/r1
Frans de Jonge 2 years ago committed by GitHub
parent 785eb5f3ef
commit 1c8ab19f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -61,7 +61,7 @@ function GetText_mt.__call(gettext, msgid)
return gettext.translation[msgid] or gettext.wrapUntranslated(msgid)
end
local function c_escape(what)
local function c_escape(what_full, what)
if what == "\n" then return ""
elseif what == "a" then return "\a"
elseif what == "b" then return "\b"
@ -72,7 +72,7 @@ local function c_escape(what)
elseif what == "v" then return "\v"
elseif what == "0" then return "\0" -- shouldn't happen, though
else
return what
return what_full
end
end
@ -138,7 +138,7 @@ end
local function addTranslation(msgctxt, msgid, msgstr, n)
-- translated string
local unescaped_string = string.gsub(msgstr, "\\(.)", c_escape)
local unescaped_string = string.gsub(msgstr, "(\\(.))", c_escape)
if msgctxt and msgctxt ~= "" then
if not GetText.context[msgctxt] then
GetText.context[msgctxt] = {}

Loading…
Cancel
Save