乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      lua輸入法...

       罔鳥 2022-05-05 發(fā)布于廣東

      1.農(nóng)歷

      Rime 是一個可以高度自定義的輸入法,前文講述了時間、日期、星期的定義方式

      文章鏈接:RIME輸入法獲取當前時間(一)_惜洛-Jankin的博客-CSDN博客

      現(xiàn)在介紹獲取當前農(nóng)歷時間的配置,效果如下(我定義了農(nóng)歷關(guān)鍵字):

      實現(xiàn)方式:

      ①在用戶代碼文件夾中新建一個文件夾。

       lunar_translator = require("lunar")

      ②在文件夾中的Lua中新建文件lunar.lua(此處的文件名與前面需要的內(nèi)容相同),如下加入lua代碼

       --此處獲取農(nóng)歷的代碼來自博客
       --https://blog.csdn.net/BlueMustard/article/details/120907984
       ------------------------------------------------------------------------------------
       --天干名稱
       local nLTianGan = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"}
       --地支名稱
       local nLDiZhi = {"子","丑","寅","卯","辰","巳","午", "未","申","酉","戌","亥"}
       --屬相名稱
       local nLShuXing = {"鼠","牛","虎","兔","龍","蛇", "馬","羊","猴","雞","狗","豬"}
       --農(nóng)歷日期名
       local nLDayName =
       {
           "*","初一","初二","初三","初四","初五",
           "初六","初七","初八","初九","初十",
           "十一","十二","十三","十四","十五",
           "十六","十七","十八","十九","二十",
           "廿一","廿二","廿三","廿四","廿五",
           "廿六","廿七","廿八","廿九","三十"
       }
       --農(nóng)歷月份名
       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 } }
       --轉(zhuǎn)為二進制
       function DecimalismToBinary(num)
           local str = ""
           local tmp = num
           while (tmp > 0) do
               if (tmp % 2 == 1) then
                   str = str .. "1"
               else
                   str = str .. "0"
               end
        
               tmp = math.modf(tmp / 2)
           end
           str = string.reverse(str)
           return str
       end
       --先補齊兩個數(shù)字的二進制位數(shù)
       function MakeSameLength(num1, num2)
           local str1 = DecimalismToBinary(num1)
           local str2 = DecimalismToBinary(num2)
           local len1 = string.len(str1)
           local len2 = string.len(str2)
           local len = 0
           local x = 0
        
           if (len1 > len2) then
               x = len1 - len2
               for i = 1, x do
                   str2 = "0" .. str2
               end
               len = len1
           elseif (len2 > len1) then
               x = len2 - len1
               for i = 1, x do
                   str1 = "0" .. str1
               end
               len = len2
           end
           len = len1
           return str1, str2, len
       end
       --按位與
       function BitAnd(num1, num2)
           local str1, str2, len = MakeSameLength(num1, num2)
           local rtmp = ""
           for i = 1, len do
               local st1 = tonumber(string.sub(str1, i, i))
               local st2 = tonumber(string.sub(str2, i, i))
               if(st1 == 0) then
                   rtmp = rtmp .. "0"
               else
                   if (st2 ~= 0) then
                       rtmp = rtmp .. "1"
                   else
                       rtmp = rtmp .. "0"
                   end
               end
           end
           return tonumber(rtmp,2)
       end
       --陽歷轉(zhuǎn)陰歷
       function GregorianToLunar(nSYear,nSMonth,nSDate)
           local nLYear,nLMonth,nLDay
           local i=(GregorianIsLeapYear(nSYear) == 1 and DaysToMonth366[nSMonth ] or DaysToMonth365[nSMonth ])+nSDate
           nLYear = nSYear
           local yearInfo
           local yearInfo2
           if nLYear == 2101 then
               nLYear = nLYear -1
               i=i+(GregorianIsLeapYear(nLYear) == 1 and 366 or 365)
               yearInfo=GetYearInfo(nLYear,1)
               yearInfo2=GetYearInfo(nLYear,2)
           else
               yearInfo=GetYearInfo(nLYear,1)
               yearInfo2=GetYearInfo(nLYear,2)
               if nSMonth <yearInfo or (nSMonth == yearInfo and nSDate < yearInfo2) then
                   nLYear=nLYear-1
                   i=i+(GregorianIsLeapYear(nLYear) == 1 and 366 or 365)
                   yearInfo=GetYearInfo(nLYear,1)
                   yearInfo2=GetYearInfo(nLYear,2)
               end
           end
           i=i-DaysToMonth365[yearInfo]
           i=i-yearInfo2+1
           local num=32768
           local yearInfo3=GetYearInfo(nLYear,3)
           local num2=(BitAnd(yearInfo3,num)) ~= 0 and 30 or 29
           nLMonth=1
           while(i>num2) do
               i=i-num2
               nLMonth=nLMonth+1
               num=num /2
               num2=(BitAnd(yearInfo3,num)) ~= 0 and 30 or 29
           end
           nLDay=i
       --生成農(nóng)歷天干、地支、屬相 ==> 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
           --生成農(nóng)歷月、日 ==> nLDate--*/
           if nLMonth < 1 then
               nLDate =  "閏" .. nLMonName[(-1 * nLMonth) + 1]
           else
               nLDate = nLMonName[nLMonth+1]
           end
           nLDate =  nongLi..nLDate .. "月" .. nLDayName[nLDay+1]
           return nLYear,nLMonth,nLDay,nLDate
       end
        
       --公歷閏年
       function GregorianIsLeapYear(year)
           if year%4 ~= 0 then
               return 0
           end
           if year%100 ~= 0 then
               return  1
           end
           if year%400 == 0 then
               return 1
           end
           return 0
       end
        
       function GetYearInfo(lunarYear,index)
           if lunarYear < 1901 or lunarYear > 2100 then
               return
           end
           lunarYear=lunarYear+1
           index=index+1
           return DateLunarInfo[lunarYear- 1901][index]
       end
       --此處獲取農(nóng)歷的代碼來自博客
       --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=nLDate
       date2=nLYear.."年"..nLMonth.."月"..nLDay.."日"
       ---------------------------------------------------------------------------------
       --農(nóng)歷
       local function translator(input, seg)
          if (input == "lunar") then
             yield(Candidate("date", seg.start, seg._end, date1, " "))
             yield(Candidate("date", seg.start, seg._end, date2, " "))
          end
       end
       return translator

      這里的語言代碼用lua語言編寫而成,若有一定基礎根據(jù)自己的需求調(diào)整響應代碼。

      ③在用戶配置文件中開啟(*.custom.yaml文件)

       #若你的配置文件中有engine/translator,則后面直接加入代碼
           - lua_translator@lunar_translator
       #若你的配置文件中無engine/translator項,則加入
         engine/+:
           translators/+:
             - lua_translator@lunar_translator
       #此處@后面的名稱必需與rime.lua文件中的定義名稱一致

      2.全時間

      此處配置獲取當前全時間,定義的關(guān)鍵字是allt,效果如下:

      代碼實現(xiàn)如下: ①在rime.lua文件中加入如下

       alltime_translator = require("alltime")

      ②在文件夾中的Lua中新建文件alltime.lu(這里的文件名主要與前面需要的內(nèi)容相同),如下加入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." 
           end
           if day_w=="1" then
             day_w1="星期一" 
             day_w2="Monday" 
             day_w3="Mon." 
           end
           if day_w=="2" then
             day_w1="星期二" 
             day_w2="Tuesday" 
             day_w3="Tues." 
           end
           if day_w=="3" then 
             day_w1="星期三" 
             day_w2="Wednesday" 
             day_w3="Wed." 
           end
           if day_w=="4" then 
             day_w1="星期四" 
             day_w2="Thursday" 
             day_w3="Thur." 
           end
           if day_w=="5" then 
             day_w1="星期五"  
             day_w2="Friday" 
             day_w3="Fri." 
           end
           if 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")+0
       num_m1=math.modf(num_m)
       num_d=os.date("%d")+0
       num_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"       symbal
           local 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"
           end
           if date_m=="02" then 
              date_m1="Feb."
              date_m2="February"
           end
           if date_m=="03" then 
              date_m1="Mar."
              date_m2="March"
           end
           if date_m=="04" then 
              date_m1="Apr."
              date_m2="April"
           end
           if date_m=="05" then 
              date_m1="May."
              date_m2="May"
           end
           if date_m=="06" then 
              date_m1="Jun."
              date_m2="June"
           end
           if date_m=="07" then 
              date_m1="Jul."
              date_m2="July"
           end
           if date_m=="08" then 
              date_m1="Aug."
              date_m2="August"
           end
           if date_m=="09" then 
              date_m1="Sept."
              date_m2="September"
           end
           if date_m=="10" then 
              date_m1="Oct."
              date_m2="October"
           end
           if date_m=="11" then 
              date_m1="Nov."
              date_m2="November"
           end
           if date_m=="12" then 
              date_m1="Dec."
              date_m2="December"
           end
       ?
            if date_d=="0" then 
              symbal="st" 
            elseif date_d=="1" then
              symbal="nd" 
            elseif date_d=="2" then 
              symbal="rd" 
            else
              symbal="th"
            end
       ?
       date_4=date_m1..""..date_d..symbal..","..date_y
       date_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_y
       date2=date_1.." "..date_t3
       date3=date_2.." "..day_w1.." "..date_t4
       ?
       yield(Candidate("date", seg.start, seg._end, date1, " "))
       yield(Candidate("date", seg.start, seg._end, date2, " "))
       yield(Candidate("date", seg.start, seg._end, date3, " "))
          end
       end
       ------------------------------------------------------------------------------------
       return translator

      ③在用戶配置文件中開啟(*.custom.yaml文件)

       #若你的配置文件中有engine/translator,則后面直接加入代碼
           - lua_translator@alltime_translator
       #若你的配置文件中無engine/translator項,則加入
         engine/+:
           translators/+:
             - lua_translator@alltime_translator
       #此處@后面的名稱必需與rime.lua文件中的定義名稱一致

      3.數(shù)字大寫

      此處配置數(shù)字大寫,定義關(guān)鍵字大寫D,再輸入即可實現(xiàn)數(shù)字大寫,效果如下:

      代碼實現(xiàn)如下: ①在rime.lua文件中加入如下

       number2_translator = require("number2")

      ②在文件夾中的Lua中新建文件編號2.lu(加入此處的文件名主要與前面的內(nèi)容相同),改成lua代碼

       --lua語言中的注釋用“--”
       --此處數(shù)字大寫的代碼參考
       --https://wubi98./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 part
       end
       local function GetPreciseDecimal(nNum, n)
           if type(nNum) ~= "number" then nNum =tonumber(nNum) end
           n = n or 0;
           n = math.floor(n)
           if n < 0 then n = 0 end
           local nDecimal = 10 ^ n
           local nTemp = math.floor(nNum * nDecimal);
           local nRet = nTemp / nDecimal;
           return nRet;
       end
       local function decimal_func(str, posMap, valMap)
           local dec
           posMap = 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) end
           dec = string.gsub(dec, "0+$", "")
           if dec == "" then return "整" end
           local result = ""
           for pos =1, #dec do
               local val = tonumber(string.sub(dec, pos, pos))
               if val~=0 then result = result .. valMap[val] .. posMap[pos] else result = result .. valMap[val] end
           end
           result=result:gsub(valMap[0]..valMap[0] ,valMap[0])
           return result:gsub(valMap[0]..valMap[0] ,valMap[0])
       end
       -- 把數(shù)字串按千分位四位數(shù)分割,進行轉(zhuǎn)換為中文
       local function formatNum(num,t)
           local digitUnit,wordFigure
           local result=""
           num=tostring(num)
           if tonumber(t) < 1 then digitUnit = {"", "十", "百","千"} else digitUnit = {"","拾","佰","仟"} end
           if tonumber(t) <1 then
               wordFigure = {"〇","一","二","三","四","五","六","七","八","九"}
           else wordFigure = {"零","壹","貳","叁","肆","伍","陸","柒","捌","玖"} end
           if string.len(num)>4 or tonumber(num)==0 then return wordFigure[1] end
           local lens=string.len(num)
           for i=1,lens do
               local n=wordFigure[tonumber(string.sub(num,-i,-i))+1]
               if n~=wordFigure[1] then result=n .. digitUnit[i] .. result else result=n .. result end
           end
           result=result:gsub(wordFigure[1]..wordFigure[1] ,wordFigure[1])
           result=result:gsub(wordFigure[1].."$","") result=result:gsub(wordFigure[1].."$","")
           return result
       end
       -- 數(shù)值轉(zhuǎn)換為中文
       function number2cnChar(num,flag,digitUnit,wordFigure)    --flag=0中文小寫反之為大寫
           local st,result
           num=tostring(num) result=""
           local num1,num2=math.modf(num)
           if tonumber(num2)==0 then
               if tonumber(flag) < 1 then
                   digitUnit = digitUnit or {[1]="萬";[2]="億"}  wordFigure = wordFigure or {[1]="〇"; [2]="一"; [3]="十"; [4]="元"}
               else
                   digitUnit = digitUnit or {[1]="萬";[2]="億"}  wordFigure = wordFigure or {[1]="零"; [2]="壹"; [3]="拾"; [4]="元"}
               end
               local 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="" end
               result=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]) end
               if result~="" then result=result .. wordFigure[4] else result="數(shù)值超限!" end
           else return "數(shù)值超限!" end
           return result
       end
       local function number2zh(num,t)
           local result,wordFigure
           result="" 
           if tonumber(t) <1 then
               wordFigure = {"〇","一","二","三","四","五","六","七","八","九"}
           else wordFigure = {"零","壹","貳","叁","肆","伍","陸","柒","捌","玖"} end
           if tostring(num)==nil then return "" end
           for pos=1,string.len(num) do
               result=result..wordFigure[tonumber(string.sub(num, pos, pos)+1)]
           end
           result=result:gsub(wordFigure[1] .. wordFigure[1],wordFigure[1])
           return result:gsub(wordFigure[1] .. wordFigure[1],wordFigure[1])
       end
       function number_translatorFunc(num)
           local numberPart=splitNumPart(num)
           local result={}
           if numberPart.dot~="" then
               table.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),"〔大寫〕"})
           else
               table.insert(result,{number2cnChar(numberPart.int,0,{"萬", "億"},{"〇","一","十",""}),""})
               table.insert(result,{number2cnChar(numberPart.int,1,{"萬", "億"},{"零","壹","拾",""}),""})
           end
           table.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 result
       end
       --以上代碼參考https://wubi98./categories/%E5%B0%8F%E7%8B%BC%E6%AF%AB/
       ------------------------------------------------------------------------------------
       function translator(input, seg)
           local str,num,numberPart
           if string.match(input,"^(D+%d+)(%.?)(%d*)$")~=nil then
               str = string.gsub(input,"^(%a+)", "")  numberPart=number_translatorFunc(str)
               if #numberPart>0 then
                   for i=1,#numberPart do
                       yield(Candidate(input, seg.start, seg._end, numberPart[i][1],numberPart[i][2]))
                   end
               end
           end
       end
       return translator

      ③在用戶配置文件中開啟(*.custom.yaml文件)

      #若你的配置文件中有engine/translator,則后面直接加入代碼
          - lua_translator@number2_translator
      #若你的配置文件中無engine/translator項,則加入
        engine/+:
          translators/+:
            - lua_translator@number2_translator
      #此處@后面的名稱必需與rime.lua文件中的定義名稱一致

      以上配置文件的合集打包可在公眾號獲取。

      以上今天的內(nèi)容對您的這個問題,任何問題的評論都可以讓您成為我寫作的意義所在,有我的私信或私信。當然點與關(guān)注點也是我最大的支持與,也是我繼續(xù)寫作的動力源泉。

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多