feat(lua): use translator/keep_comments: true to prevent lua from erasing pinyin comments
This commit is contained in:
parent
7d5952d97a
commit
98d18b74df
@ -13,6 +13,7 @@ local M = {}
|
|||||||
|
|
||||||
function M.init(env)
|
function M.init(env)
|
||||||
local config = env.engine.schema.config
|
local config = env.engine.schema.config
|
||||||
|
env.keep_comment = config:get_bool('translator/keep_comments')
|
||||||
local delimiter = config:get_string('speller/delimiter')
|
local delimiter = config:get_string('speller/delimiter')
|
||||||
if delimiter and #delimiter > 0 and delimiter:sub(1,1) ~= ' ' then
|
if delimiter and #delimiter > 0 and delimiter:sub(1,1) ~= ' ' then
|
||||||
env.delimiter = delimiter:sub(1,1)
|
env.delimiter = delimiter:sub(1,1)
|
||||||
@ -122,16 +123,21 @@ function M.func(input, env)
|
|||||||
-- cand.comment 是目前输入的词汇的完整拼音
|
-- cand.comment 是目前输入的词汇的完整拼音
|
||||||
local pinyin = cand.comment:match("^[(.-)]$")
|
local pinyin = cand.comment:match("^[(.-)]$")
|
||||||
if pinyin and #pinyin > 0 then
|
if pinyin and #pinyin > 0 then
|
||||||
|
local correction_pinyin = pinyin
|
||||||
if env.delimiter then
|
if env.delimiter then
|
||||||
pinyin = pinyin:gsub(env.delimiter,' ')
|
correction_pinyin = correction_pinyin:gsub(env.delimiter,' ')
|
||||||
end
|
end
|
||||||
local c = M.corrections[pinyin]
|
local c = M.corrections[correction_pinyin]
|
||||||
if c and cand.text == c.text then
|
if c and cand.text == c.text then
|
||||||
cand:get_genuine().comment = string.gsub(M.style, "{comment}", c.comment)
|
cand:get_genuine().comment = string.gsub(M.style, "{comment}", c.comment)
|
||||||
|
else
|
||||||
|
if env.keep_comment then
|
||||||
|
cand:get_genuine().comment = string.gsub(M.style, "{comment}", pinyin)
|
||||||
else
|
else
|
||||||
cand:get_genuine().comment = ""
|
cand:get_genuine().comment = ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
yield(cand)
|
yield(cand)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user