Modul:zh-han
Bu modul uchun Modul:zh-han/doc nomli hujjat sahifasini yaratishingiz mumkin
local export = {}
local cangjie = {
['A']='日',['B']='月',['C']='金',['D']='木',['E']='水',['F']='火',['G']='土',
['H']='竹',['I']='戈',['J']='十',['K']='大',['L']='中',['M']='一',['N']='弓',
['O']='人',['P']='心',['Q']='手',['R']='口',
['S']='尸',['T']='廿',['U']='山',['V']='女',['W']='田',['X']='X',['Y']='卜',['Z']='Z'
}
local radicals = {
"一","丨","丶","丿","乙","亅",
"二","亠","人","儿","入","八","冂","冖","冫","几","凵","刀","力","勹","匕","匚","匸","十","卜","卩","厂","厶","又",
"口","囗","土","士","夂","夊","夕","大","女","子","宀","寸","小","尢","尸","屮","山","巛","工","己","巾","干","幺","广","廴","廾","弋","弓","彐","彡","彳",
"心","戈","戶","手","支","攴","文","斗","斤","方","无","日","曰","月","木","欠","止","歹","殳","毋","比","毛","氏","气","水","火","爪","父","爻","爿","片","牙","牛","犬",
"玄","玉","瓜","瓦","甘","生","用","田","疋","疒","癶","白","皮","皿","目","矛","矢","石","示","禸","禾","穴","立",
"竹","米","糸","缶","网","羊","羽","老","而","耒","耳","聿","肉","臣","自","至","臼","舌","舛","舟","艮","色","艸","虍","虫","血","行","衣","西",
"見","角","言","谷","豆","豕","豸","貝","赤","走","足","身","車","辛","辰","辵","邑","酉","釆","里",
"金","長","門","阜","隶","隹","雨","靑","非",
"面","革","韋","韭","音","頁","風","飛","食","首","香",
"馬","骨","高","髟","鬥","鬯","鬲","鬼",
"魚","鳥","鹵","鹿","麥","麻",
"黃","黍","黑","黹",
"黽","鼎","鼓","鼠",
"鼻","齊",
"齒",
"龍","龜",
"龠"
}
local simplified_radical = {
['讠']='言',['门']='門',['饣']='食',['飞']='飛',['马']='馬',['见']='見',['贝']='貝',['纟']='糸',['车']='車',['长']='長',['韦']='韋',['风']='風',['钅']='金',['鸟']='鳥',['龙']='龍',['页']='頁',['齐']='齊',['麦']='麥',['龟']='龜',['鱼']='魚',['黾']='黽',['鼡']='鼠',['齿']='齒'
}
function mul_link(term)
return '[[' .. term .. '#Translingual|' .. term .. ']]'
end
function radical(name,number,variant)
number = number or '1'
local len = mw.ustring.len(number)
local padleft = (len == 2 and '0' .. number or (len == 1 and '00' .. number or number))
PAGENAME = PAGENAME or mw.title.getCurrentTitle().text
local text = '<div class="noprint" style="border:solid #aaa 1px;margin:0;font-size:74%;background:#f9f3f6;width:120px;padding:3px;spacing:0;text-align:center;float:right"><div style="float:left">[[Image:Commons-logo.svg|24px|none|link=Commons:Category:Radical ' .. padleft .. ']]</div>[[Commons:Category:Radical ' .. padleft .. "-0|See images of <br>'''Radical " .. number .. " <big>" .. ((name and name ~= '') and PAGENAME or '※') .. "</big>''']]</div>"
if name == PAGENAME then
text = text .. '[[Category:Han character radicals| ]]'
else
if variant and variant ~= '' then
text = text .. '[[Category:Han character radicals| ]]'
else
text = text .. '[[Category:Han char without var| ]]'
end
end
return text
end
function export.simp(frame)
local args = frame:getParent().args
local trad = args[1] or ''; if trad == '' then trad = require("Module:zh/data").st[mw.title.getCurrentTitle().text] or mw.title.getCurrentTitle().text end
local alt = args['a'] or ''
local from = {args['f'] or '',args['f2'] or ''}
local to = {args['t'] or '',args['t2'] or ''}
if from[1] == '' and to[1] ~= '' then from[1] = trad end
local text = {}
local result = 'Simplified from ' .. mul_link(trad)
if alt ~= '' then
result = result .. ' and ' .. mul_link(alt)
end
for i=1,2 do
if from[i] ~= '' then
if to[i] == '' then
table.insert(text,mul_link(from[i]) .. " → a component which cannot be displayed independently[[Category:Kenny's testing category 3]]")
elseif to[i] == ' ' or to[i] == ' ' then
table.insert(text,'elimination of ' .. mul_link(from[i]))
else
table.insert(text,mul_link(from[i]) .. ' → ' .. mul_link(to[i]))
end
end
end
if #text > 0 then
result = result .. ' (' .. table.concat(text,' and '):gsub('and elimination of','and') .. ')'
end
return result
end
function export.character(frame)
local args = frame:getParent().args
if radicals[tonumber(args['rn'])] ~= (simplified_radical[args['rad']] or args['rad']) then error('Radical number (rn) and radical (rad) do not match') end
local text = ''
local as = tostring(tonumber(args['as'] or '-1'))
PAGENAME = PAGENAME or mw.title.getCurrentTitle().text
if as == '0' then
text = radical(args['rad'],args['rn'],(args['var'] or ''))
end
text = text .. '<strong lang="zh" class="Hani headword">' .. (args['head'] or PAGENAME) .. "</strong> (''radical " .. (args['rn'] or '') .. "'' [[Index:Chinese radical/" .. (args['rad'] or '') .. '|' .. (args['rad'] or ' ') .. ']]+' .. as
if args['asj'] and args['asj'] ~= '' then
text = text .. " ''in Chinese'', " .. (args['rad'] or '') .. '+' .. tonumber(args['asj']) .. " ''in Japanese''"
end
text = text .. ", "
if args['snj'] and args['snj'] ~= '' then
text = text .. "''in Chinese'' "
end
text = text .. (args['sn'] or '') .. " ''stroke"
if args['sn'] and args['sn'] == '1' then else text = text .. 's' end
text = text .. "''"
if args['snj'] and args['snj'] ~= '' then
text = text .. ", ''in Japanese'' " .. args['snj'] .. " ''stroke"
if args['snj'] and args['snj'] == '1' then else text = text .. 's' end
text = text .. "''"
end
if args['canj'] and args['canj'] ~= '' then
local canj = args['canj']
local canj_split = mw.text.split(canj,',')
for i=1,#canj_split do
if mw.ustring.match(canj_split[i],'^[A-Z]+$') then --confirmed UTF-8, use string library instead of ustring
canj_split[i] = canj_split[i]:gsub('[%(%)]','')
canj_split[i] = canj_split[i]:gsub('[A-Z]',cangjie) .. ' ([[Index:Chinese Cangjie/' .. canj_split[i]:sub(1,1):lower() .. '|' .. canj_split[i] .. ']])'
else
text = text .. "[[Category:Han char unsimplified usage]]"
end
end
text = text .. ", ''[[Index:Chinese Cangjie|cangjie input]]'' " .. table.concat(canj_split,', ')
end
if args['four'] and args['four'] ~= '' then
local four = args['four']
if not four:match('[<>]') then
four = four:gsub('(%d)(%d%d%d)(%d)','[[Index:Chinese four corner/%1|%1%2<sub>%3</sub>]]')
else
text = text .. "[[Category:Han char unsimplified usage]]"
end
text = text .. ", ''[[Index:Chinese four corner|four-corner]]'' " .. four
end
if args['ids'] and args['ids'] ~= '' then
local ids = args['ids']
if not mw.ustring.match(ids,'[%[%]]') then
ids = mw.ustring.gsub(ids,'([^⿻⿴⿵⿶⿷⿸⿹⿺⿰⿱⿲⿳])','[[%1]]')
ids = mw.ustring.gsub(ids,'%[%[([^⿻⿴⿵⿶⿷⿸⿹⿺⿰⿱⿲⿳])%]%]%[%[%1%]%]%[%[%1%]%]','[[%1]]%1%1')
ids = mw.ustring.gsub(ids,'%[%[([^⿻⿴⿵⿶⿷⿸⿹⿺⿰⿱⿲⿳])%]%]%[%[%1%]%]','[[%1]]%1')
end
text = text .. ", ''composition'' " .. ids
end
text = text .. ')'
if args['rad'] and args['rad'] ~= '' then
if mw.title.getCurrentTitle().nsText == '' then
text = text .. "[[Category:Han script characters|" .. args['rad'] .. args['as'] .. PAGENAME .. "]]"
end
else
if mw.title.getCurrentTitle().nsText == '' then
text = text .. "[[Category:Chinese terms needing attention|q]]"
end
end
if not args['as'] or args['as'] == '' then
text = text .. "[[Category:Chinese terms needing attention|a]]"
elseif mw.ustring.len(args['as']) ~= 2 then
text = text .. "[[Category:Invalid parameter in Han char]]"
end
if not args['rn'] or args['rn'] == '' then
text = text .. "[[Category:Chinese terms needing attention|n]]"
end
if not args['sn'] or args['sn'] == '' then
text = text .. "[[Category:Chinese terms needing attention|s]]"
elseif mw.ustring.sub(args['sn'],1,1) == '0' then
text = text .. "[[Category:Invalid parameter in Han char]]"
end
if not args['ids'] or args['ids'] == '' then
text = text .. "[[Category:Kenny's testing category 4]]"
end
if not args['four'] or args['four'] == '' then
text = text .. "[[Category:Kenny's testing category 5]]"
end
return text
end
return export