RIME中州韵输入法lua配置获取当前时间(二)
1.农历
Rime是一款可以高度自定义的输入法,前文讲述了time,date,week的定义方式
文章链接:RIME输入法获取当前时间(一)_惜洛-Jankin的博客-CSDN博客
现介绍获取当前农历时间的配置,效果如下(我定义了lunar关键字):
实现如下:
①在用户文件夹中新建一个rime.lua文件加入如下代码
lunar_translator = require("lunar")
②在文件夹Lua中新建文件lunar.lua(此处的文件名必需与上文require中的内容相同),加入如下lua代码:
--此处获取农历的代码来自博客--https://blog.csdn.net/BlueMustard/article/details/120907984--------------------------------------------------------------------------------------天干名称local nLTianGan = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"}--地支名称local nLDiZhi = {"子","丑","寅","卯","辰","巳","午", "未","申","酉","戌","亥"}--属相名称local nLShuXing = {"鼠","牛","虎","兔","龙","蛇", "马","羊","猴","鸡","狗","猪"}--农历日期名local nLDayName ={"*","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"}--农历月份名local nLMonName = {"*","正","二","三","四","五","六", "七","八","九","十","十一","腊"}local DaysToMonth366={ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }local DaysToMonth365= { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }local DateLunarInfo= { { 0, 2, 19, 19168 }, { 0, 2, 8, 42352 }, { 5, 1, 29, 21096 }, { 0, 2, 16, 53856 }, { 0, 2, 4, 55632 }, { 4, 1, 25, 27304 },{ 0, 2, 13, 22176 }, { 0, 2, 2, 39632 }, { 2, 1, 22, 19176 }, { 0, 2, 10, 19168 }, { 6, 1, 30, 42200 }, { 0, 2, 18, 42192 },{ 0, 2, 6, 53840 }, { 5, 1, 26, 54568 }, { 0, 2, 14, 46400 }, { 0, 2, 3, 54944 }, { 2, 1, 23, 38608 }, { 0, 2, 11, 38320 },{ 7, 2, 1, 18872 }, { 0, 2, 20, 18800 }, { 0, 2, 8, 42160 }, { 5, 1, 28, 45656 }, { 0, 2, 16, 27216 }, { 0, 2, 5, 27968 },{ 4, 1, 24, 44456 }, { 0, 2, 13, 11104 }, { 0, 2, 2, 38256 }, { 2, 1, 23, 18808 }, { 0, 2, 10, 18800 }, { 6, 1, 30, 25776 },{ 0, 2, 17, 54432 }, { 0, 2, 6, 59984 }, { 5, 1, 26, 27976 }, { 0, 2, 14, 23248 }, { 0, 2, 4, 11104 }, { 3, 1, 24, 37744 },{ 0, 2, 11, 37600 }, { 7, 1, 31, 51560 }, { 0, 2, 19, 51536 }, { 0, 2, 8, 54432 }, { 6, 1, 27, 55888 }, { 0, 2, 15, 46416 },{ 0, 2, 5, 22176 }, { 4, 1, 25, 43736 }, { 0, 2, 13, 9680 }, { 0, 2, 2, 37584 }, { 2, 1, 22, 51544 }, { 0, 2, 10, 43344 },{ 7, 1, 29, 46248 }, { 0, 2, 17, 27808 }, { 0, 2, 6, 46416 }, { 5, 1, 27, 21928 }, { 0, 2, 14, 19872 }, { 0, 2, 3, 42416 },{ 3, 1, 24, 21176 }, { 0, 2, 12, 21168 }, { 8, 1, 31, 43344 }, { 0, 2, 18, 59728 }, { 0, 2, 8, 27296 }, { 6, 1, 28, 44368 },{ 0, 2, 15, 43856 }, { 0, 2, 5, 19296 }, { 4, 1, 25, 42352 }, { 0, 2, 13, 42352 }, { 0, 2, 2, 21088 }, { 3, 1, 21, 59696 },{ 0, 2, 9, 55632 }, { 7, 1, 30, 23208 }, { 0, 2, 17, 22176 }, { 0, 2, 6, 38608 }, { 5, 1, 27, 19176 }, { 0, 2, 15, 19152 },{ 0, 2, 3, 42192 }, { 4, 1, 23, 53864 }, { 0, 2, 11, 53840 }, { 8, 1, 31, 54568 }, { 0, 2, 18, 46400 }, { 0, 2, 7, 46752 },{ 6, 1, 28, 38608 }, { 0, 2, 16, 38320 }, { 0, 2, 5, 18864 }, { 4, 1, 25, 42168 }, { 0, 2, 13, 42160 }, { 10, 2, 2, 45656 },{ 0, 2, 20, 27216 }, { 0, 2, 9, 27968 }, { 6, 1, 29, 44448 }, { 0, 2, 17, 43872 }, { 0, 2, 6, 38256 }, { 5, 1, 27, 18808 },{ 0, 2, 15, 18800 }, { 0, 2, 4, 25776 }, { 3, 1, 23, 27216 }, { 0, 2, 10, 59984 }, { 8, 1, 31, 27432 }, { 0, 2, 19, 23232 },{ 0, 2, 7, 43872 }, { 5, 1, 28, 37736 }, { 0, 2, 16, 37600 }, { 0, 2, 5, 51552 }, { 4, 1, 24, 54440 }, { 0, 2, 12, 54432 },{ 0, 2, 1, 55888 }, { 2, 1, 22, 23208 }, { 0, 2, 9, 22176 }, { 7, 1, 29, 43736 }, { 0, 2, 18, 9680 }, { 0, 2, 7, 37584 },{ 5, 1, 26, 51544 }, { 0, 2, 14, 43344 }, { 0, 2, 3, 46240 }, { 4, 1, 23, 46416 }, { 0, 2, 10, 44368 }, { 9, 1, 31, 21928 },{ 0, 2, 19, 19360 }, { 0, 2, 8, 42416 }, { 6, 1, 28, 21176 }, { 0, 2, 16, 21168 }, { 0, 2, 5, 43312 }, { 4, 1, 25, 29864 },{ 0, 2, 12, 27296 }, { 0, 2, 1, 44368 }, { 2, 1, 22, 19880 }, { 0, 2, 10, 19296 }, { 6, 1, 29, 42352 }, { 0, 2, 17, 42208 },{ 0, 2, 6, 53856 }, { 5, 1, 26, 59696 }, { 0, 2, 13, 54576 }, { 0, 2, 3, 23200 }, { 3, 1, 23, 27472 }, { 0, 2, 11, 38608 },{ 11, 1, 31, 19176 }, { 0, 2, 19, 19152 }, { 0, 2, 8, 42192 }, { 6, 1, 28, 53848 }, { 0, 2, 15, 53840 }, { 0, 2, 4, 54560 },{ 5, 1, 24, 55968 }, { 0, 2, 12, 46496 }, { 0, 2, 1, 22224 }, { 2, 1, 22, 19160 }, { 0, 2, 10, 18864 }, { 7, 1, 30, 42168 },{ 0, 2, 17, 42160 }, { 0, 2, 6, 43600 }, { 5, 1, 26, 46376 }, { 0, 2, 14, 27936 }, { 0, 2, 2, 44448 }, { 3, 1, 23, 21936 },{ 0, 2, 11, 37744 }, { 8, 2, 1, 18808 }, { 0, 2, 19, 18800 }, { 0, 2, 8, 25776 }, { 6, 1, 28, 27216 }, { 0, 2, 15, 59984 },{ 0, 2, 4, 27424 }, { 4, 1, 24, 43872 }, { 0, 2, 12, 43744 }, { 0, 2, 2, 37600 }, { 3, 1, 21, 51568 }, { 0, 2, 9, 51552 },{ 7, 1, 29, 54440 }, { 0, 2, 17, 54432 }, { 0, 2, 5, 55888 }, { 5, 1, 26, 23208 }, { 0, 2, 14, 22176 }, { 0, 2, 3, 42704 },{ 4, 1, 23, 21224 }, { 0, 2, 11, 21200 }, { 8, 1, 31, 43352 }, { 0, 2, 19, 43344 }, { 0, 2, 7, 46240 }, { 6, 1, 27, 46416 },{ 0, 2, 15, 44368 }, { 0, 2, 5, 21920 }, { 4, 1, 24, 42448 }, { 0, 2, 12, 42416 }, { 0, 2, 2, 21168 }, { 3, 1, 22, 43320 },{ 0, 2, 9, 26928 }, { 7, 1, 29, 29336 }, { 0, 2, 17, 27296 }, { 0, 2, 6, 44368 }, { 5, 1, 26, 19880 }, { 0, 2, 14, 19296 },{ 0, 2, 3, 42352 }, { 4, 1, 24, 21104 }, { 0, 2, 10, 53856 }, { 8, 1, 30, 59696 }, { 0, 2, 18, 54560 }, { 0, 2, 7, 55968 },{ 6, 1, 27, 27472 }, { 0, 2, 15, 22224 }, { 0, 2, 5, 19168 }, { 4, 1, 25, 42216 }, { 0, 2, 12, 42192 }, { 0, 2, 1, 53584 },{ 2, 1, 21, 55592 }, { 0, 2, 9, 54560 } }--转为二进制function DecimalismToBinary(num)local str = ""local tmp = numwhile (tmp > 0) doif (tmp % 2 == 1) thenstr = str .. "1"elsestr = str .. "0"endtmp = math.modf(tmp / 2)endstr = string.reverse(str)return strend--先补齐两个数字的二进制位数function MakeSameLength(num1, num2)local str1 = DecimalismToBinary(num1)local str2 = DecimalismToBinary(num2)local len1 = string.len(str1)local len2 = string.len(str2)local len = 0local x = 0if (len1 > len2) thenx = len1 - len2for i = 1, x dostr2 = "0" .. str2endlen = len1elseif (len2 > len1) thenx = len2 - len1for i = 1, x dostr1 = "0" .. str1endlen = len2endlen = len1return str1, str2, lenend--按位与function BitAnd(num1, num2)local str1, str2, len = MakeSameLength(num1, num2)local rtmp = ""for i = 1, len dolocal st1 = tonumber(string.sub(str1, i, i))local st2 = tonumber(string.sub(str2, i, i))if(st1 == 0) thenrtmp = rtmp .. "0"elseif (st2 ~= 0) thenrtmp = rtmp .. "1"elsertmp = rtmp .. "0"endendendreturn tonumber(rtmp,2)end--阳历转阴历function GregorianToLunar(nSYear,nSMonth,nSDate)local nLYear,nLMonth,nLDaylocal i=(GregorianIsLeapYear(nSYear) == 1 and DaysToMonth366[nSMonth ] or DaysToMonth365[nSMonth ])+nSDatenLYear = nSYearlocal yearInfolocal yearInfo2if nLYear == 2101 thennLYear = nLYear -1i=i+(GregorianIsLeapYear(nLYear) == 1 and 366 or 365)yearInfo=GetYearInfo(nLYear,1)yearInfo2=GetYearInfo(nLYear,2)elseyearInfo=GetYearInfo(nLYear,1)yearInfo2=GetYearInfo(nLYear,2)if nSMonth <yearInfo or (nSMonth == yearInfo and nSDate < yearInfo2) thennLYear=nLYear-1i=i+(GregorianIsLeapYear(nLYear) == 1 and 366 or 365)yearInfo=GetYearInfo(nLYear,1)yearInfo2=GetYearInfo(nLYear,2)endendi=i-DaysToMonth365[yearInfo]i=i-yearInfo2+1local num=32768local yearInfo3=GetYearInfo(nLYear,3)local num2=(BitAnd(yearInfo3,num)) ~= 0 and 30 or 29nLMonth=1while(i>num2) doi=i-num2nLMonth=nLMonth+1num=num /2num2=(BitAnd(yearInfo3,num)) ~= 0 and 30 or 29endnLDay=i--生成农历天干、地支、属相 ==> nongLi--local shuXing = nLShuXing[(((nLYear - 4) % 60) % 12) + 1]local nongLi = shuXing .. '(' .. nLTianGan[(((nLYear - 4) % 60) % 10)+1] .. nLDiZhi[(((nLYear - 4) % 60) % 12) + 1] .. ')年'local nLDate--生成农历月、日 ==> nLDate--*/if nLMonth < 1 thennLDate = "闰" .. nLMonName[(-1 * nLMonth) + 1]elsenLDate = nLMonName[nLMonth+1]endnLDate = nongLi..nLDate .. "月" .. nLDayName[nLDay+1]return nLYear,nLMonth,nLDay,nLDateend--公历闰年function GregorianIsLeapYear(year)if year%4 ~= 0 thenreturn 0endif year%100 ~= 0 thenreturn 1endif year%400 == 0 thenreturn 1endreturn 0endfunction GetYearInfo(lunarYear,index)if lunarYear < 1901 or lunarYear > 2100 thenreturnendlunarYear=lunarYear+1index=index+1return DateLunarInfo[lunarYear- 1901][index]end--此处获取农历的代码来自博客--https://blog.csdn.net/BlueMustard/article/details/120907984------------------------------------------------------------------------------------date_y=os.date("%Y") --取年date_y= tonumber(date_y)date_m=os.date("%m") --取月date_m= tonumber(date_m)date_d=os.date("%d") --取日date_d= tonumber(date_d)nLYear,nLMonth,nLDay,nLDate =GregorianToLunar(date_y,date_m,date_d)nLYear,nLMonth,nLDay,nLDate =GregorianToLunar(date_y,date_m,date_d)date1=nLDatedate2=nLYear.."年"..nLMonth.."月"..nLDay.."日"-----------------------------------------------------------------------------------农历local function translator(input, seg)if (input == "lunar") thenyield(Candidate("date", seg.start, seg._end, date1, " "))yield(Candidate("date", seg.start, seg._end, date2, " "))endendreturn translator
此处代码用lua语言编写而成,若有一定语言基础,根据自己的需求调整响应代码。
③在用户配置文件中开启(*.custom.yaml文件)
#若你的配置文件中有engine/translator,则后面直接加入代码- lua_translator@lunar_translator#若你的配置文件中无engine/translator项,则加入engine/+:translators/+:- lua_translator@lunar_translator#此处@后面的名称必需与rime.lua文件中的定义名称一致
2.全时间
此处配置获取当前全时间,定义的关键字是allt,效果如下:
实现如下:①在rime.lua文件加入如下代码
alltime_translator = require("alltime")
②在文件夹Lua中新建文件alltime.lua(此处的文件名必需与上文require中的内容相同),加入如下lua代码:
--lua语言中的注释用“--”--**********************************************************************************local function translator(input, seg)if (input == "allt"or input == "time") then--------------------------------------------------------------------------------------星期 day_w1="星期日" day_w2="Sunday" day_w3="Sun." local day_w=os.date("%w")local day_w1=""local day_w2=""local day_w3=""if day_w=="0" then day_w1="星期日" day_w2="Sunday" day_w3="Sun." endif day_w=="1" thenday_w1="星期一" day_w2="Monday" day_w3="Mon." endif day_w=="2" thenday_w1="星期二" day_w2="Tuesday" day_w3="Tues." endif day_w=="3" then day_w1="星期三" day_w2="Wednesday" day_w3="Wed." endif day_w=="4" then day_w1="星期四" day_w2="Thursday" day_w3="Thur." endif day_w=="5" then day_w1="星期五" day_w2="Friday" day_w3="Fri." endif day_w=="6" then day_w1="星期六" day_w2="Saturday" day_w3="Sat." end--------------------------------------------------------------------------------------普通日期1,类似2020年02月04日date_0=os.date("%Y/%m/%d")date_1=os.date("%Y-%m-%d")date_y0=os.date("%Y") --取年date_m0=os.date("%m") --取月date_d0=os.date("%d") --取日--去零日和月tostring(num_m1) tostring(num_d1)num_m=os.date("%m")+0num_m1=math.modf(num_m)num_d=os.date("%d")+0num_d1=math.modf(num_d)date_y2=os.date("%Y") --取年date_m2=tostring(num_m1) --取月date_d2=tostring(num_d1) --取日date_2=os.date("%Y年")..tostring(num_m1).."月"..tostring(num_d1).."日"--------------------------------------------------------------------------------------------------------英文日期 date_m1="Jan." date_m2="January" symballocal date_d=os.date("%d")local date_m=os.date("%m")local date_y=os.date("%Y")local date_m1=""local date_m2=""if date_m=="01" then date_m1="Jan."date_m2="January"endif date_m=="02" then date_m1="Feb."date_m2="February"endif date_m=="03" then date_m1="Mar."date_m2="March"endif date_m=="04" then date_m1="Apr."date_m2="April"endif date_m=="05" then date_m1="May."date_m2="May"endif date_m=="06" then date_m1="Jun."date_m2="June"endif date_m=="07" then date_m1="Jul."date_m2="July"endif date_m=="08" then date_m1="Aug."date_m2="August"endif date_m=="09" then date_m1="Sept."date_m2="September"endif date_m=="10" then date_m1="Oct."date_m2="October"endif date_m=="11" then date_m1="Nov."date_m2="November"endif date_m=="12" then date_m1="Dec."date_m2="December"endif date_d=="0" then symbal="st" elseif date_d=="1" thensymbal="nd" elseif date_d=="2" then symbal="rd" elsesymbal="th"enddate_4=date_m1..""..date_d..symbal..","..date_ydate_5=date_m2.." "..date_d..symbal..","..date_y------------------------------------------------------------------------------时间date_t1=os.date("%H:%M")date_t2=os.date("%H点%M分")date_t3=os.date("%H:%M:%S")date_t4=os.date("%H点%M分%S秒")-----------------------------------------------------------------------date1=day_w3.." "..date_m1.." "..date_d..symbal..", "..date_t3..", "..date_ydate2=date_1.." "..date_t3date3=date_2.." "..day_w1.." "..date_t4yield(Candidate("date", seg.start, seg._end, date1, " "))yield(Candidate("date", seg.start, seg._end, date2, " "))yield(Candidate("date", seg.start, seg._end, date3, " "))endend------------------------------------------------------------------------------------return translator
③在用户配置文件中开启(*.custom.yaml文件)
#若你的配置文件中有engine/translator,则后面直接加入代码- lua_translator@alltime_translator#若你的配置文件中无engine/translator项,则加入engine/+:translators/+:- lua_translator@alltime_translator#此处@后面的名称必需与rime.lua文件中的定义名称一致
3.数字大写
此处配置数字大写转换,定义关键字为大写字母D,再输入数字即可实现数字大写,效果如下:
实现如下:①在rime.lua文件加入如下代码
number2_translator = require("number2")
②在文件夹Lua中新建文件number2.lua(此处的文件名必需与上文require中的内容相同),加入如下lua代码:
--lua语言中的注释用“--”--此处数字大写的代码参考--https://wubi98.gitee.io/categories/%E5%B0%8F%E7%8B%BC%E6%AF%AB/local function splitNumPart(str)local part = {}part.int, part.dot, part.dec = string.match(str, "^(%d*)(%.?)(%d*)")return partendlocal function GetPreciseDecimal(nNum, n)if type(nNum) ~= "number" then nNum =tonumber(nNum) endn = n or 0;n = math.floor(n)if n < 0 then n = 0 endlocal nDecimal = 10 ^ nlocal nTemp = math.floor(nNum * nDecimal);local nRet = nTemp / nDecimal;return nRet;endlocal function decimal_func(str, posMap, valMap)local decposMap = posMap or {[1]="角"; [2]="分"; [3]="厘"; [4]="毫"}valMap = valMap or {[0]="零"; "壹"; "贰"; "叁" ;"肆"; "伍"; "陆"; "柒"; "捌"; "玖"}if #str>4 then dec = string.sub(tostring(str), 1, 4) else dec =tostring(str) enddec = string.gsub(dec, "0+$", "")if dec == "" then return "整" endlocal result = ""for pos =1, #dec dolocal val = tonumber(string.sub(dec, pos, pos))if val~=0 then result = result .. valMap[val] .. posMap[pos] else result = result .. valMap[val] endendresult=result:gsub(valMap[0]..valMap[0] ,valMap[0])return result:gsub(valMap[0]..valMap[0] ,valMap[0])end-- 把数字串按千分位四位数分割,进行转换为中文local function formatNum(num,t)local digitUnit,wordFigurelocal result=""num=tostring(num)if tonumber(t) < 1 then digitUnit = {"", "十", "百","千"} else digitUnit = {"","拾","佰","仟"} endif tonumber(t) <1 thenwordFigure = {"〇","一","二","三","四","五","六","七","八","九"}else wordFigure = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"} endif string.len(num)>4 or tonumber(num)==0 then return wordFigure[1] endlocal lens=string.len(num)for i=1,lens dolocal n=wordFigure[tonumber(string.sub(num,-i,-i))+1]if n~=wordFigure[1] then result=n .. digitUnit[i] .. result else result=n .. result endendresult=result:gsub(wordFigure[1]..wordFigure[1] ,wordFigure[1])result=result:gsub(wordFigure[1].."$","") result=result:gsub(wordFigure[1].."$","")return resultend-- 数值转换为中文function number2cnChar(num,flag,digitUnit,wordFigure) --flag=0中文小写反之为大写local st,resultnum=tostring(num) result=""local num1,num2=math.modf(num)if tonumber(num2)==0 thenif tonumber(flag) < 1 thendigitUnit = digitUnit or {[1]="万";[2]="亿"} wordFigure = wordFigure or {[1]="〇"; [2]="一"; [3]="十"; [4]="元"}elsedigitUnit = digitUnit or {[1]="万";[2]="亿"} wordFigure = wordFigure or {[1]="零"; [2]="壹"; [3]="拾"; [4]="元"}endlocal lens=string.len(num1)if lens<5 then result=formatNum(num1,flag) elseif lens<9 then result=formatNum(string.sub(num1,1,-5),flag) .. digitUnit[1].. formatNum(string.sub(num1,-4,-1),flag)elseif lens<13 then result=formatNum(string.sub(num1,1,-9),flag) .. digitUnit[2] .. formatNum(string.sub(num1,-8,-5),flag) .. digitUnit[1] .. formatNum(string.sub(num1,-4,-1),flag) else result="" endresult=result:gsub("^" .. wordFigure[1],"") result=result:gsub(wordFigure[1] .. digitUnit[1],"") result=result:gsub(wordFigure[1] .. digitUnit[2],"")result=result:gsub(wordFigure[1] .. wordFigure[1],wordFigure[1]) result=result:gsub(wordFigure[1] .. "$","")if lens>4 then result=result:gsub("^"..wordFigure[2].. wordFigure[3],wordFigure[3]) endif result~="" then result=result .. wordFigure[4] else result="数值超限!" endelse return "数值超限!" endreturn resultendlocal function number2zh(num,t)local result,wordFigureresult="" if tonumber(t) <1 thenwordFigure = {"〇","一","二","三","四","五","六","七","八","九"}else wordFigure = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"} endif tostring(num)==nil then return "" endfor pos=1,string.len(num) doresult=result..wordFigure[tonumber(string.sub(num, pos, pos)+1)]endresult=result:gsub(wordFigure[1] .. wordFigure[1],wordFigure[1])return result:gsub(wordFigure[1] .. wordFigure[1],wordFigure[1])endfunction number_translatorFunc(num)local numberPart=splitNumPart(num)local result={}if numberPart.dot~="" thentable.insert(result,{number2cnChar(numberPart.int,0,{"万", "亿"},{"〇","一","十","点"})..number2zh(numberPart.dec,0),""})table.insert(result,{number2cnChar(numberPart.int,1,{"萬", "億"},{"〇","一","十","点"})..number2zh(numberPart.dec,1),""})-- table.insert(result,{number2cnChar(numberPart.int,1,{"萬", "億"},{"〇","一","十","点"})..number2zh(numberPart.dec,1),"〔大写〕"})elsetable.insert(result,{number2cnChar(numberPart.int,0,{"万", "亿"},{"〇","一","十",""}),""})table.insert(result,{number2cnChar(numberPart.int,1,{"萬", "億"},{"零","壹","拾",""}),""})endtable.insert(result,{number2cnChar(numberPart.int,1)..decimal_func(numberPart.dec,{[1]="角"; [2]="分"; [3]="厘"; [4]="毫"},{[0]="零"; "壹"; "贰"; "叁" ;"肆"; "伍"; "陆"; "柒"; "捌"; "玖"}),""})table.insert(result,{number2cnChar(numberPart.int,0)..decimal_func(numberPart.dec,{[1]="角"; [2]="分"; [3]="厘"; [4]="毫"},{[0]="〇"; "一"; "二"; "三" ;"四"; "五"; "六"; "七"; "八"; "九"}),""})return resultend--以上代码参考https://wubi98.gitee.io/categories/%E5%B0%8F%E7%8B%BC%E6%AF%AB/------------------------------------------------------------------------------------function translator(input, seg)local str,num,numberPartif string.match(input,"^(D+%d+)(%.?)(%d*)$")~=nil thenstr = string.gsub(input,"^(%a+)", "") numberPart=number_translatorFunc(str)if #numberPart>0 thenfor i=1,#numberPart doyield(Candidate(input, seg.start, seg._end, numberPart[i][1],numberPart[i][2]))endendendendreturn translator
③在用户配置文件中开启(*.custom.yaml文件)
#若你的配置文件中有engine/translator,则后面直接加入代码- lua_translator@number2_translator
#若你的配置文件中无engine/translator项,则加入engine/+:translators/+:- lua_translator@number2_translator
#此处@后面的名称必需与rime.lua文件中的定义名称一致
以上配置文件的合集打包可在公众号获取。
以上就是今天的内容,这篇文章能帮到你是我写作的意义所在,有任何问题可以评论或私信。当然,您的点赞与关注也是对我最大的支持与肯定,也是我继续写作的动力源泉。
了解更多教程可关注公众号惜洛IT
RIME中州韵输入法lua配置获取当前时间(二)相关推荐
- RIME中州韵输入法lua配置获取当前时间(一)
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能. 1.TIME Rime是一款可以高度自定义的输入法,相关教程可以查看往期文章,关于时间获取是指输入一个指定关键字,输出当前时间,效果 ...
- Fedora29 安装/配置 小狼毫输入法(RIME | 中州韵输入法引擎)
Fedora29 安装/配置 小狼毫输入法(RIME | 中州韵输入法引擎) 聪明的输入法懂我心意. 通过dnf安装ibus输入法框架下的rime sudo dnf install ibus-rime ...
- rime中州韵输入法源码初识----分工与安装
2021SC@SDUSC 最近大三开始有一门创新实训的课程,让我们组队去研究一项自己感兴趣项目,最终决定选择rime输入法. 首先简单介绍这款输入法,他有三个版本 windows 的叫小狼毫 ,Mac ...
- RIME中州韵输入法引擎学习
RIME中州韵输入法引擎 1. 中州韵输入法引擎官网 官网:https://rime.im/ 2. 源码包介绍 源码库:https://github.com/rime/librime rime配置管理 ...
- RIME中州韵输入法如何实现中英文翻译功能
Rime输入法通过配置词库,可以实现中英文翻译功能,输入中文意思输出单词,输入英文也可以出现中文翻译,看效果: 配置 首先下载词库(个人整理词库在公众号惜洛IT,回复rime)在词库配置文件中加入词 ...
- 【Linux】Ubuntu中文输入法的配置和系统时间的设置
默认情况下ubuntu只有英文输入法,没有中文输入法.要想使用中文输入法,需要配置下载中文输入法的源. 1.找到 Settings 方法一: 方法二: 2.选择 Region & Langua ...
- 解决VScode 与 Linux Rime 中州韵输入法 CTRL+~ 热键冲突
Ctrl + ~ 为 VScode 调出集成终端的快捷键.同时也是 Rime 输入法方案菜单的快捷键.VScode 的快捷键会被覆盖. 因为 rime 热键 F4 与 CTRL + ~ 作用相同, 这 ...
- Linux在fcitx框架下添加小鹤音形(挂载在中州韵输入法下)
Linux在fcitx框架下添加小鹤音形(挂载在中州韵输入法下) 0.注意该方法会完全替换掉中洲韵中的其他输入法,如果还需要其他输入法,可以用sudo apt install fcitx-然后按下Ta ...
- 小程序获取企业微信二维码,使用联系我插件配置企业微信二维码
通过配置获取企业微信二维码总共分为五步: 第一步:登录企业微信管理后台,查询企业微信的企业ID(corpid)和Secret(corpsecret); 第二步:获取access_token: 第三步: ...
- Rime输入法引擎配置( 小狼毫输入法常用设置)
版本 Linux下叫中州韵ibus-rime Windows下叫小狼毫 Mac下叫鼠须管 Rime 中的數據文件分佈及作用(配置) https://github.com/rime/home/wiki/ ...
最新文章
- First use cursor and initially understand it
- java基础,没事常看看(一)类、对象、引用
- 【TensorFlow-windows】(七) CNN之VGG-net的测试
- 使用ApiPost测试接口时需要先登录的接口怎么办(基于Cookie)?
- python趋势回归_Python 回归分析 - 树懒学堂
- Atitit postgresql data type 数据类型与mysql对应表 数据库常用数据类型 	Postgre	Mysql	 整数	intgreter	Int	 小数	numeric	FL
- DUET DISPLAY实现分屏,IPAD做WINDOWS显示器副屏
- 专业的笔记本测试软件,专业软件性能测试
- 【安全热点】阿里巴巴月饼门,观点两极化,孰对孰错?
- 【贪玩巴斯】传感器与检测技术 (二)「半导体传感器基础」2021-09-30
- 计算机编程abs是什么意思,VB编程中的“Abs”是什么意思?
- WEB端工程环境安装
- 基于雷电模拟器利用python制作手游脚本 (神都夜行录,古剑奇谭木语人) (一)
- C语言实验——三角形
- 大数据告诉你,北上广深哪里最容易吃到你的家乡味儿?
- 招商银行如何关闭大众版和手机银行转账功能
- 暨南大学计算机考研大纲,2021暨南大学考研大纲参考书目汇总
- 3D游戏中人物换装解决方案
- 苹果手机相片删除了怎么恢复回来?恢复照片,3分钟搞定!
- 如何区分针对视频的分类,场景识别,动作识别三个概念?