diff --git a/double_pinyin_flypy.schema.yaml b/double_pinyin_flypy.schema.yaml index 845ce79..452c1ab 100644 --- a/double_pinyin_flypy.schema.yaml +++ b/double_pinyin_flypy.schema.yaml @@ -77,9 +77,7 @@ engine: translators: - punct_translator # ※ 轉換標點符號 - script_translator - - lua_translator@*date_translator # 日期Lua - - lua_translator@*time_translator # 时间Lua - - lua_translator@*week_translator # 星期Lua + - lua_translator@*mint_date_time_translator # 时间、日期、星期、月份 - lua_translator@*number_translator # 金额大小写 - lua_translator@*chineseLunarCalendar_translator # 农历 - table_translator@melt_eng # 英文输入(作为子翻译器,优先级需要比原生的低) diff --git a/lua/date_translator.lua b/lua/date_translator.lua deleted file mode 100644 index 642c6c5..0000000 --- a/lua/date_translator.lua +++ /dev/null @@ -1,70 +0,0 @@ -local function translator(input, seg) - if (input ~= "date") then return end - - local date_y = os.date("%Y") -- Year - local date_m = os.date("%m") -- Month - local date_d = os.date("%d") -- Day - - local num_m1 = tonumber(date_m) - local num_d1 = tonumber(date_d) - - -- Helper function to create a Candidate - local function create_candidate(date_str) - local candidate = Candidate("date", seg.start, seg._end, date_str, " ") - candidate.quality = 100 - yield(candidate) - end - - -- Create the various date formats - create_candidate(os.date("%Y年%m月%d日")) -- Format: 2022年01月02日 - create_candidate(os.date("%Y年") .. num_m1 .. "月" .. num_d1 .. "日") -- Format: 2022年1月1日 - create_candidate(num_m1 .. "月" .. num_d1 .. "日") -- Format: 1月1日 - create_candidate(os.date("%Y/%m/%d")) -- Format: 2022/01/02 - create_candidate(os.date("%Y-%m-%d")) -- Format: 2022-01-02 - - -- Chinese big date - local chinese_num = { - ["1"]="一", ["2"]="二", ["3"]="三", ["4"]="四", ["5"]="五", - ["6"]="六", ["7"]="七", ["8"]="八", ["9"]="九", ["0"]="〇" - } - local chinese_month = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"} - - local date_y_chinese = date_y:gsub("%d", chinese_num) .. "年" - local date_m_chinese = chinese_month[num_m1] - local date_d_chinese = tostring(num_d1):gsub("%d", chinese_num) .. "日" - - if num_d1 > 9 then - date_d_chinese = string.sub(date_d_chinese, 1, 3) .. "十" .. string.sub(date_d_chinese, 4) - end - - create_candidate(date_y_chinese .. date_m_chinese .. date_d_chinese) - - -- English date - local english_month = { - "Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", - "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec." - } - - local english_month_full = { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" - } - - local date_m_english = english_month[num_m1] - local date_m_english_full = english_month_full[num_m1] - - local ordinal = "th" - if date_d == "01" or date_d == "21" or date_d == "31" then - ordinal = "st" - elseif date_d == "02" or date_d == "22" then - ordinal = "nd" - elseif date_d == "03" or date_d == "23" then - ordinal = "rd" - end - - create_candidate(date_m_english .. " " .. date_d .. ordinal .. ", " .. date_y) - create_candidate(date_m_english_full .. " " .. date_d .. ordinal .. ", " .. date_y) - create_candidate(os.date("%Y%m%d")) -- Format: 20220102 -end - -return translator \ No newline at end of file diff --git a/lua/mint_date_time_translator.lua b/lua/mint_date_time_translator.lua new file mode 100644 index 0000000..f452669 --- /dev/null +++ b/lua/mint_date_time_translator.lua @@ -0,0 +1,113 @@ +--[[ + 时间、日期、星期快捷输入 + 示例: + 1. 输入 week 可以出现当前的星期 + 2. 输入 date 可以出现当前的日期 + 3. 输入 time 可以出现当前的时间 + 4. 输入 month 可以出现当前的月份 + 5. 输入 datetime 可以出现当前时间节点 + + 参考借鉴: https://github.com/KyleBing/rime-wubi86-jidian + + Mintimate 修改内容: + 1. 适配权重 + 2. 注解添加 + +--]] + + +local function make_hight_quality_candidate(inputText, startSeg, endSeg, text, comment) + -- Candidate(type, start, end, text, comment) + local candidate = Candidate(inputText, startSeg, endSeg, text, comment) + candidate.quality = 125 + -- 调整优先级 + return candidate +end + + +function mint_date_time_translator(input, seg) + + -- 日期格式说明: + + -- %a abbreviated weekday name (e.g., Wed) + -- %A full weekday name (e.g., Wednesday) + -- %b abbreviated month name (e.g., Sep) + -- %B full month name (e.g., September) + -- %c date and time (e.g., 09/16/98 23:48:10) + -- %d day of the month (16) [01-31] + -- %H hour, using a 24-hour clock (23) [00-23] + -- %I hour, using a 12-hour clock (11) [01-12] + -- %M minute (48) [00-59] + -- %m month (09) [01-12] + -- %p either "am" or "pm" (pm) + -- %S second (10) [00-61] + -- %w weekday (3) [0-6 = Sunday-Saturday] + -- %W week number in year (48) [01-52] + -- %x date (e.g., 09/16/98) + -- %X time (e.g., 23:48:10) + -- %Y full year (1998) + -- %y two-digit year (98) [00-99] + -- %% the character `%´ + + -- 输入完整日期 + if (input == "datetime") then + yield(make_hight_quality_candidate("date", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), "yyyy-MM-dd HH:mm:ss")) + end + + -- 输入日期 + if (input == "date") then + yield(make_hight_quality_candidate("date", seg.start, seg._end, os.date("%Y%m%d"), "yyyyMMdd")) + yield(make_hight_quality_candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), "yyyy-MM-dd")) + yield(make_hight_quality_candidate("date", seg.start, seg._end, os.date("%Y/%m/%d"), "yyyy/MM/dd")) + yield(make_hight_quality_candidate("date", seg.start, seg._end, os.date("%Y.%m.%d"), "yyyy.MM.dd")) + yield(make_hight_quality_candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), "中文简写")) + -- Chinese big date + local chinese_num = { + ["1"]="一", ["2"]="二", ["3"]="三", ["4"]="四", ["5"]="五", + ["6"]="六", ["7"]="七", ["8"]="八", ["9"]="九", ["0"]="〇" + } + local chinese_month = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"} + + local date_y_chinese = os.date("%Y"):gsub("%d", chinese_num) .. "年" + local date_m_chinese = chinese_month[tonumber(os.date("%m"))] + local date_d_chinese = tostring(tonumber(os.date("%d"))):gsub("%d", chinese_num) .. "日" + + if tonumber(os.date("%d")) > 9 then + date_d_chinese = string.sub(date_d_chinese, 1, 3) .. "十" .. string.sub(date_d_chinese, 4) + end + + yield(make_hight_quality_candidate("date", seg.start, seg._end, date_y_chinese .. date_m_chinese .. date_d_chinese, "中文大写")) + + yield(make_hight_quality_candidate("date", seg.start, seg._end, os.date("%m-%d-%Y"), "MM-dd-yyyy")) + + end + + -- 输入时间 + if (input == "time") then + yield(make_hight_quality_candidate("time", seg.start, seg._end, os.date("%H:%M"), "HH:mm")) + yield(make_hight_quality_candidate("time", seg.start, seg._end, os.date("%Y%m%d%H%M%S"), "yyyyMMddHHmmss")) + yield(make_hight_quality_candidate("time", seg.start, seg._end, os.date("%H:%M:%S"), "HH:mm:ss")) + yield(make_hight_quality_candidate("time", seg.start, seg._end, os.date("%H点%M分%S秒"), "中文")) + + end + + -- 输入星期 + -- -- @JiandanDream + -- -- https://github.com/KyleBing/rime-wubi86-jidian/issues/54 + if (input == "week") then + local weekTab = {'日', '一', '二', '三', '四', '五', '六'} + yield(make_hight_quality_candidate("week", seg.start, seg._end, "周"..weekTab[tonumber(os.date("%w")+1)], "星期")) + yield(make_hight_quality_candidate("week", seg.start, seg._end, os.date("%A"), "")) + yield(make_hight_quality_candidate("week", seg.start, seg._end, "星期"..weekTab[tonumber(os.date("%w")+1)], "星期")) + yield(make_hight_quality_candidate("week", seg.start, seg._end, os.date("%a"), "缩写")) + yield(make_hight_quality_candidate("week", seg.start, seg._end, os.date("%W"), "周数")) + end + + -- 输入月份英文 + if (input == "month") then + yield(make_hight_quality_candidate("month", seg.start, seg._end, os.date("%B"), "全称")) + yield(make_hight_quality_candidate("month", seg.start, seg._end, os.date("%b"), "缩写")) + end +end + +return mint_date_time_translator diff --git a/lua/time_translator.lua b/lua/time_translator.lua deleted file mode 100644 index 84a74eb..0000000 --- a/lua/time_translator.lua +++ /dev/null @@ -1,14 +0,0 @@ -local function translator(input, seg) - if input == "time" then - -- 定义时间格式数组 - local formats = {"%H:%M", "%H点%M分", "%H:%M:%S", "%H点%M分%S秒"} - -- 遍历时间格式数组,生成候选项 - for _, format in ipairs(formats) do - -- 生成候选项,并设置quality为100 - local candidate = Candidate("time", seg.start, seg._end, os.date(format), " ") - candidate.quality = 100 - yield(candidate) - end - end -end -return translator \ No newline at end of file diff --git a/lua/week_translator.lua b/lua/week_translator.lua deleted file mode 100644 index 7462d0b..0000000 --- a/lua/week_translator.lua +++ /dev/null @@ -1,21 +0,0 @@ -local function translator(input, seg) - if input == "week" then - local days_cn = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"} - local days_en = {"Sun.", "Mon.", "Tues.", "Wed.", "Thur.", "Fri.", "Sat."} - local day = os.date("%w") + 1 -- 星期日的编号是0,需要加1 - for i = 1, 3 do - local week_cn = Candidate("date", seg.start, seg._end, days_cn[day], " ") - week_cn.quality = 100 - yield(week_cn) - local week_en = Candidate("date", seg.start, seg._end, days_en[day], " ") - week_en.quality = 100 - yield(week_en) - day = day % 7 + 1 -- 循环获取下一个星期几的名称 - end - local week = Candidate("week", seg.start, seg._end, os.date("%w"), "") - week.quality = 100 - yield(week) - end -end - -return translator \ No newline at end of file diff --git a/rime_mint.schema.yaml b/rime_mint.schema.yaml index 5450ed7..738c2d2 100755 --- a/rime_mint.schema.yaml +++ b/rime_mint.schema.yaml @@ -69,9 +69,7 @@ engine: translators: - punct_translator # ※ 轉換標點符號 - script_translator - - lua_translator@*date_translator # 日期Lua - - lua_translator@*time_translator # 时间Lua - - lua_translator@*week_translator # 星期Lua + - lua_translator@*mint_date_time_translator # 时间、日期、星期、月份 - lua_translator@*number_translator # 金额大小写 - lua_translator@*chineseLunarCalendar_translator # 农历 - table_translator@melt_eng # 英文输入(作为子翻译器,优先级需要比原生的低) diff --git a/rime_mint_flypy.schema.yaml b/rime_mint_flypy.schema.yaml index 25195cc..77998ee 100755 --- a/rime_mint_flypy.schema.yaml +++ b/rime_mint_flypy.schema.yaml @@ -69,9 +69,7 @@ engine: translators: - punct_translator # ※ 轉換標點符號 - script_translator - - lua_translator@*date_translator # 日期Lua - - lua_translator@*time_translator # 时间Lua - - lua_translator@*week_translator # 星期Lua + - lua_translator@*mint_date_time_translator # 时间、日期、星期、月份 - lua_translator@*number_translator # 金额大小写 - lua_translator@*chineseLunarCalendar_translator # 农历 - table_translator@melt_eng # 英文输入(作为子翻译器,优先级需要比原生的低) diff --git a/terra_pinyin.custom.yaml b/terra_pinyin.custom.yaml index 2148911..d10ca86 100755 --- a/terra_pinyin.custom.yaml +++ b/terra_pinyin.custom.yaml @@ -62,9 +62,7 @@ patch: - punct_segmentor - fallback_segmentor translators: - - lua_translator@*date_translator # 日期Lua - - lua_translator@*time_translator # 时间Lua - - lua_translator@*week_translator # 星期Lua + - lua_translator@*mint_date_time_translator # 时间、日期、星期、月份 - lua_translator@*number_translator # 金额大小写 - lua_translator@*chineseLunarCalendar_translator # 农历 - punct_translator diff --git a/wubi98_mint.schema.yaml b/wubi98_mint.schema.yaml index cd97fb7..723feab 100755 --- a/wubi98_mint.schema.yaml +++ b/wubi98_mint.schema.yaml @@ -55,18 +55,16 @@ engine: - punct_segmentor - fallback_segmentor translators: - - punct_translator # ※ 轉換標點符號 + - punct_translator # ※ 轉換標點符號 - script_translator - - lua_translator@*date_translator # 日期Lua - - lua_translator@*time_translator # 时间Lua - - lua_translator@*week_translator # 星期Lua - - lua_translator@*number_translator # 金额大小写 - - table_translator@melt_eng # 英文输入(作为子翻译器,优先级需要比原生的低) - # - echo_translator # ※ 没有候选词,返回字符 + - lua_translator@*mint_date_time_translator # 时间、日期、星期、月份 + - lua_translator@*number_translator # 金额大小写 + - table_translator@melt_eng # 英文输入(作为子翻译器,优先级需要比原生的低) + # - echo_translator # ※ 没有候选词,返回字符 - reverse_lookup_translator@wubi86_jidian - reverse_lookup_translator@chaizi - reverse_lookup_translator@stroke - # - reverse_lookup_translator # 反查模块,多标签情况下去除 + # - reverse_lookup_translator # 反查模块,多标签情况下去除 speller: auto_select: true