Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议修改一下我修改的rime.lua #93

Open
AHSHA98 opened this issue May 20, 2023 · 1 comment
Open

建议修改一下我修改的rime.lua #93

AHSHA98 opened this issue May 20, 2023 · 1 comment

Comments

@AHSHA98
Copy link

AHSHA98 commented May 20, 2023

我修改的rime.lua可以实现“二〇二三年五月二十日”这样的日期

function date_translator(input, seg)
if (input == "date" or input == "rq") then
--- Candidate(type, start, end, text, comment)
local dateTab = {'一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十', '二十一', '二十二', '二十三', '二十四', '二十五', '二十六', '二十七', '二十八', '二十九', '三十', '三十一'}
local yearTab = {[0] = '〇', '一', '二', '三', '四', '五', '六', '七', '八', '九'}
local year_tbl = ""
for i = 1 , 4 do
year_tbl = year_tbl..yearTab[tonumber(string.sub(tonumber(os.date("%Y")), i, i))]
end
yield(Candidate("date", seg.start, seg._end, os.date("%Y.%m.%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
yield(Candidate("date", seg.start, seg._end, year_tbl.."年"..dateTab[tonumber(os.date("%m"))].."月"..dateTab[tonumber(os.date("%d"))].."日", ""))
yield(Candidate("date", seg.start, seg._end, os.date("%m-%d"), ""))
yield(Candidate("date", seg.start, seg._end, os.date("%Y/%m/%d"), ""))
end
if (input == "time" or input == "sj") then
--- Candidate(type, start, end, text, comment)
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M"), ""))
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M:%S"), ""))
end
if (input == "week" or input == "xq") then
local weakTab = {'日', '一', '二', '三', '四', '五', '六'}
yield(Candidate("week", seg.start, seg._end, "周"..weakTab[tonumber(os.date("%w")+1)], ""))
yield(Candidate("week", seg.start, seg._end, "星期"..weakTab[tonumber(os.date("%w")+1)], ""))
yield(Candidate("week", seg.start, seg._end, "礼拜"..weakTab[tonumber(os.date("%w")+1)], ""))
end
if (input == "nyr" or input == "ydt") then
yield(Candidate("date", seg.start, seg._end, os.date("%Y.%m%d.%H%M"), ""))
end
end

--- 过滤器:单字在先
function single_char_first_filter(input)
local l = {}
for cand in input:iter() do
if (utf8.len(cand.text) == 1) then
yield(cand)
else
table.insert(l, cand)
end
end
for cand in ipairs(l) do
yield(cand)
end
end

@Chfeng2021
Copy link

Chfeng2021 commented May 20, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants