La documentation pour ce module peut être créée à Module:bac à sable/Assassas77-2/Documentation
local M = {}
local m_skeys = nil
local len = mw.ustring.len
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local cmn_pron = nil
local function format_Chinese_text(text) return '<span class="Hani" lang="zh">' .. text .. '</span>' end
local function format_rom(text) return text and '<i><span class="tr Latn">' .. text .. '</span></i>' or nil end
local function format_gloss(text) return text and '“' .. text .. '”' or nil end
local tones = ''
local pos_aliases_title = {
= "Noun",
= "Proper noun",
= "Proper noun",
= "Pronoun",
= "Verb",
= "Adjective",
= "Adjective",
= "Adverb",
= "Preposition",
= "Postposition",
= "Conjunction",
= "Particle",
= "Suffix",
= "Proverb",
= "Idiom",
= "Idiom",
= "Idiom",
= "Phrase",
= "Interjection",
= "Classifier",
= "Numeral",
= "Abbreviation",
= "Determiner",
}
local pos_aliases_head = {
= "noun",
= "proper noun",
= "proper noun",
= "verb",
= "adj",
= "post",
= "con",
= "particle",
= "pronoun",
= "proverb",
= "idiom",
= "idiom",
= "idiom",
= "phrase",
= "interj",
= "abbr",
= "cls",
= "det",
}
local function replace_chars(s, tab)
return gsub(s, ".", tab)
end
function M.sortkey_conv(f)
local m_sort_data = mw.loadData("Module:zh/data/sortkey")
local rs = type(f) == 'table' and f.args or f
local ch = sub(rs,1,1)
ch = m_sort_data.sortkeys or ch
return ch .. sub(rs, 2, len(rs))
end
function M.py_detone(f)
local text = type(f) == 'table' and f.args or f
return mw.ustring.toNFC(gsub(mw.ustring.toNFD(text), tones, ''))
end
function M.py_transf(f)
local text = type(f) == 'table' and f.args or f
return M.py_detone(text) .. M.tone_determ(text)
end
function M.tone_determ(f)
local text = type(f) == 'table' and f.args or f
text = mw.ustring.toNFD(text)
local tone_num = { = '1', = '2', = '3', = '4' }
return tone_num or '5'
end
function M.ts_determ(f)
local m_ts_data = mw.loadData("Module:zh/data/ts")
local m_st_data = mw.loadData("Module:zh/data/st")
local text = type(f) == 'table' and f.args or f
local i = 0
for cp in mw.ustring.gcodepoint(text) do
local ch = mw.ustring.char(cp)
if m_ts_data.ts then return 'trad' end
if m_st_data.st then if i > 1 then return 'simp' else i = i + 1 end end
end
return (i > 0 and 'simp' or 'both')
end
function M.ts(f)
local m_ts_data = mw.loadData("Module:zh/data/ts")
local text = type(f) == 'table' and f.args or f
text = replace_chars(text, m_ts_data.ts)
return text
end
function M.st(f)
local m_st_data = mw.loadData("Module:zh/data/st")
local text = type(f) == 'table' and f.args or f
text = replace_chars(text, m_st_data.st)
return text
end
function M.py(text,comp,pos,p,is_erhua)
local m_cmn_pron = mw.loadData("Module:zh/data/cmn-pron")
if not is_erhua then is_erhua = false end
if type(text) == 'table' then text,comp,pos,p,is_erhua = text.args,text.args,text.args,text.args,text.args end
comp = comp or ''
local q = {}
local sum = 0
local length = len(text)
if is_erhua then length = length - 1 end
local textconv = text
text = ''
if comp ~= '' and comp ~= '12' and comp ~= '21' and not ((pos == 'cy' or pos == 'Idiom' or pos == 'idiom') and length == 4) and not is_erhua then
for i = 1, len(comp) do
sum = sum + tonumber(sub(comp,i,i))
q = 'y'
end
end
if not p then p={} end
local initial = true
for i = 1, length do
if p and p ~= '' then --pronunciation supplied
text = text .. p
else
local char = sub(textconv,i,i)
char = m_cmn_pron.py or m_cmn_pron.py or char
if is_erhua or initial or not mw.ustring.find(char,'^') then
text = text .. char
else
text = text .. "'" .. char
end
initial = char == sub(textconv,i,i) and sub(textconv,i-3,i) ~= "</b>" --the second condition checks for closing bold tag
end
if q == 'y' and i ~= length and not is_erhua then text = text .. ' ' end
end
if is_erhua then text = text .. 'r' end
if pos == 'pn' or pos == 'propn' then
local characters = mw.text.split(text,' ')
for i=1,#characters do
characters = mw.language.getContentLanguage():ucfirst(characters)
end
text = table.concat(characters,' ')
end
return text
end
function M.py_er(text,comp,pos,p)
return M.py(text,comp,pos,p,true)
end
function M.pytemp(text,comp,pos,p,is_erhua)
local m_cmn_pron = mw.loadData("Module:zh/data/cmn-pron")
local wordlist_1, wordlist_2, wordlist_3 = mw.loadData("Module:zh/data/wordlist/1"), mw.loadData("Module:zh/data/wordlist/2"), mw.loadData("Module:zh/data/wordlist/3")
if not is_erhua then is_erhua = false end
if type(text) == 'table' then text,comp,pos = text.args,text.args,text.args or 'n' end
comp = comp or ''
local q = {}
local sum = 0
local wordlist_result = wordlist_1 or wordlist_2 or wordlist_3 or nil
local moe_pron = wordlist_result and mw.text.split(wordlist_result, " ") or {}
local textconv = M.ts(text)
local length = len(text)
if is_erhua == true then
length = length - 1
textconv = sub(textconv, 1, length)
end
text = ''
if comp ~= '' and comp ~= '12' and comp ~= '21' and not is_erhua then
for i = 1, len(comp) do
sum = sum + tonumber(sub(comp,i,i))
q = 'y'
end
end
if not p then p={} end
for i = 1, length do
if p and p ~= '' then --pronunciation supplied
text = text .. p
else
local char = sub(textconv,i,i)
if mw.ustring.find(char,'') then
text = text .. char
else
char = moe_pron or m_cmn_pron.py or char
if i ~= 1 and mw.ustring.find(char,'^') then
char = "'" .. char
end
text = text .. char
end
end
if q == 'y' and i ~= length and not is_erhua and pos ~= 'cy' then text = text .. ' ' end
end
text = gsub(text," '"," ")
if pos == 'pn' or pos == 'propn' then
local characters = mw.text.split(text,' ')
for i = 1, #characters do
characters = mw.language.getContentLanguage():ucfirst(characters)
end
text = table.concat(characters,' ')
end
return text
end
function M.pytemp_er(text,comp,pos,p)
return M.pytemp(text,comp,pos,p,true)
end
function M.pywordconv(text,p)
local m_cmn_pron = mw.loadData("Module:zh/data/cmn-pron")
if type(text) == 'table' then text = text.args end
local textconv = M.ts(text)
local length = len(text)
text = ''
if not p then p = {} for i = 1, 20 do p = '' end end
for i = 1, length do
if p ~= '' then
text = text .. M.py_transf(p)
else
local char = sub(textconv,i,i)
local cpy = m_cmn_pron.py or char
text = text .. M.py_transf(cpy)
end
end
return text
end
function M.pywordconv_er(text,p)
local m_cmn_pron = mw.loadData("Module:zh/data/cmn-pron")
if type(text) == 'table' then text = text.args end
local length = len(text) - 1
local textconv = sub(M.ts(text),1,length)
text = ''
if not p then p={} for i=1,20 do p='' end end
for i = 1,length do
if p ~= '' then
if i == length then p = p .. 'r' end
text = text .. M.py_transf(p)
else
local char = sub(textconv,i,i)
local cpy = m_cmn_pron.py or char
if i == length then cpy = cpy .. 'r' end
text = text .. M.py_transf(cpy)
end
end
return text
end
function M.decomp(text,comp)
if type(text) == 'table' then text,comp = text.args,text.args or '' end
comp = comp or tostring(len(text))
local num = tonumber(comp)
local char = sub(text,num,num)
return char
end
function M.compdecomp(title,comp)
if type(title) == 'table' then title,comp = title.args,title.args end
comp = comp or ''
local start = 1
local finish = 1
local sum = 0
local text = ''
local p={}
local textlen = len(title)
if comp == '' then
for _ = 1, textlen do
comp = comp .. '1'
end
end
for i = 1, len(comp) do
p = tonumber(sub(comp,i,i))
sum = sum + p
end
if sum ~= textlen then
comp = ''
for j = 1,textlen do
p = tonumber(1)
comp = comp .. '1'
end
end
for i = 1, len(comp) do
if i ~= 1 then start = start + p end
finish = start + p - 1
text = (text .. ']')
end
return text
end
function M.compdecompetym(title,comp)
if type(title) == 'table' then title,comp = title.args,title.args end
comp = comp or ''
local start = 1
local finish = 1
local sum = 0
local text = ''
local p={}
local textlen = len(title)
if comp == '' then
for _ = 1, textlen do
comp = (comp .. '1')
end
end
for i = 1, len(comp) do
p = tonumber(sub(comp,i,i))
sum = sum + p
end
if sum ~= textlen then
comp = ''
for j = 1,textlen do
p = tonumber(1)
comp = (comp .. '1')
end
end
for i = 1, len(comp) do
if i ~= 1 then start = start + p end
finish = start + p - 1
if i ~= 1 then text = (text .. '|') end
text = (text .. sub(title,start,finish))
end
return text
end
function M.hzbox(title,comp,e,alt,gloss,lit,t2)
if type(title) == 'table' then title,comp = title.args,title.args end
local id = M.ts_determ(title)
local text = '{{zh-forms'
if e and e ~= "" then text = text .. '|' .. e end
if id == 'trad' then
text = text .. '|s=' .. M.ts(title)
end
text = text .. ((t2 and t2 ~= "") and ('|t2=' .. t2) or '')
text = text .. ((comp and comp ~= "") and ('|type=' .. comp) or '')
text = text .. ((alt and alt ~= "") and '|alt=' .. alt or '')
text = text .. ((gloss and gloss ~= "") and '|gloss=' .. gloss or '')
text = text .. ((lit and lit ~= "") and '|lit=' .. lit or '')
return text .. '}}'
end
function M.hzbox_er(title)
if type(title) == 'table' then title = title.args end
local length = len(title)
local id
if sub(title, length, length) == '兒' then id = 'trad' else id = 'simp' end
title = sub(title, 1, length-1)
local text = '{{zh-hanzi-box|'
if id == 'simp' then
text = (text .. ']]|]}}')
else
text = (text .. ']|]]}}')
end
return text
end
function M.sort(title)
local m_cmn_pron = mw.loadData("Module:zh/data/cmn-pron")
if type(title) == 'table' then title = title.args end
local text = ''
local length = len(title)
title = M.ts(title)
for i = 1, length do
local charpy = sub(title,i,i)
charpy = m_cmn_pron.py or charpy
text = text .. M.py_transf(charpy)
end
return text
end
function M.postitle(pos)
pos = pos or ''
if pos == '' then pos = 'n' end
return pos_aliases_title or pos
end
function M.poshead(pos)
pos = pos or ''
if pos == '' then pos = 'n' end
return pos_aliases_head or pos
end
-- Deprecated. Use the makeSortKey function in ] instead.
function M.skeys(title)
if m_skeys == nil then m_skeys = mw.loadData('Module:zh/data/skeys') end
if type(title) == 'table' then title = title.args end
local text = sub(title,1,1)
text = m_skeys.skeys or text
return text
end
function M.chardecomp(title)
if type(title) == 'table' then title = title.args end
local text = mw.text.split(title,"")
return table.concat(text,"|")
end
function M.semantics(text,name,sem)
if sem and sem ~= '' then
text = (text .. '\n\n====' .. name .. '====')
if name == 'Derived terms' then
text = text .. '\n{{zh-der'
for i = 1, #sem do
text = text .. '|' .. sem
end
text = text .. '}}'
else
for i = 1, #sem do
text = text .. '\n* {{zh-l|' .. sem .. '}}'
end
end
end
return text
end
function M.create_er(f)
return M.create(f,true)
end
local function checkpos(pos)
for poscode,posname in pairs(pos_aliases_head) do
if pos == posname then
return poscode
end
end
for poscode,posname in pairs(pos_aliases_title) do
if pos == posname then
return poscode
end
end
return pos
end
function M.headword(title,comp,pos,is_erhua)
if not is_erhua then is_erhua = false end
local is_table = (type(title) == 'table')
local p = {}
for i=4,23 do table.insert(p,(is_table and title.args or '')) end
if type(title) == 'table' then title,comp,pos = title.args,title.args,title.args end
local text = '{{zh-' .. M.poshead(pos) .. '|'
local id = M.ts_determ(title)
if id == 'both' then text = text .. 'ts' elseif id == 'simp' then text = text .. 's' else text = text .. 't' end
if is_erhua then
text = text .. '|pin=' .. M.py_er(title,comp,pos,p) .. '|pint=' .. M.pywordconv_er(title,p)
if id == 'simp' then
text = text .. '|tra=' .. M.st(title) .. '|sim=' .. title
else
text = text .. '|tra=' .. title .. '|sim=' .. M.ts(title)
end
text = text .. '}}\n\n# {{erhua form'
if def ~= '' then text = text .. '|' .. def end -- def is undefined!
else
text = text .. '|pin=' .. M.py(title,comp,pos,p) .. '|pint=' .. M.pywordconv(title,p)
if id == 'simp' then
text = text .. '|tra=' .. M.st(title) .. '|sim=' .. title
elseif id == 'trad' then
text = text .. '|tra=' .. title .. '|sim=' .. M.ts(title)
end
end
return text .. '}}'
end
function M.extract_pron(title, variety)
local tr = nil
if mw.title.new(title).exists then
local content = mw.title.new(title):getContent()
content = gsub(content, ",()", ";%1")
local template = match(content, "{{zh%-pron*|" .. variety .. "=(+)")
if template and template ~= "" then
if cmn_pron == nil then
cmn_pron = require("Module:cmn-pron")
end
tr = cmn_pron.str_analysis(template, 'link')
end
end
return tr
end
function M.link(frame, mention, args, pagename, no_transcript)
local params = {
= {},
= {},
= {},
= {},
= {},
= {},
}
if mention then
params = {}
end
local moduleCalled
if args then
moduleCalled = true
end
args = args or frame:getParent().args
if not moduleCalled then
params.required = true
end
args = require("Module:parameters").process(args, params)
if moduleCalled then
if not args then
return ""
end
end
pagename = pagename or mw.title.getCurrentTitle().text
local text, tr, gloss
if args and match(args, '') then
gloss = args
tr = args
text = args .. '/' .. args
else
text = args
if args then
tr = args
gloss = args
else
if args or (args and (match(args, '') or match(args, 'h?y???g?'))) then
tr = args
gloss = args
else
gloss = args
end
end
end
if args then
tr = args
gloss = gloss or args
end
if text then
if not text:match(']') then
local words = mw.text.split(text, "/", true)
if #words == 1 and M.ts_determ(words) == 'trad' and not match(words, '%*') then
table.insert(words, M.ts(words))
end
if not tr and not no_transcript and words and text ~= pagename then
tr = M.extract_pron(words, "m")
end
for i, word in ipairs(words) do
word = gsub(word, '%*', '')
if mention then
words = '<i class="Hani mention" lang="zh">]</i>'
--[[ (disabled to allow links to, for example, a link to 冥王星#Chinese from 冥王星#Japanese. 18 May, 2016)
elseif word == pagename then
word = format_Chinese_text('<b>' .. word .. '</b>')
]]
else
words = format_Chinese_text(']')
end
end
text = table.concat(words, "/")
elseif text:match(']') or text == pagename then
if mention then
text = '<i class="Hani mention" lang="zh">' .. gsub(text, "%*", "") .. '</i>'
else
text = format_Chinese_text(gsub(text, "%*", ""))
end
end
end
if tr == '-' or no_transcript then
tr = nil -- allow translit to be disabled: remove translit if it is "-", just like normal {{l}}
end
local notes = args
if tr or gloss or notes then
local annotations = {}
if tr then
tr = format_rom(tr)
table.insert(annotations, tr)
end
if gloss then
table.insert(annotations, format_gloss(gloss))
end
table.insert(annotations, notes)
annotations = table.concat(annotations, ", ")
text = text .. " (" .. annotations .. ")"
end
return text
end
function M.mention(frame)
return M.link(frame, true)
end
function M.check_pron(text, variety, length, entry_creation)
if type(text) == 'table' then text, variety = text.args, text.args end
if not text then
return
end
local startpoint, address = { = 51, = 19968, = 19968 }, { = 'yue-word/%03d', = 'hak-pron/%02d', = 'nan-pron/%03d' }
local unit = 1000
local first_char = sub(text, 1, 1)
local result, success, data
if length == 1 and variety == "yue" then
success, data = pcall(mw.loadData, 'Module:zh/data/Jyutping character')
else
local page_index = math.floor((mw.ustring.codepoint(first_char) - startpoint) / unit)
success, data = pcall(mw.loadData,
('Module:zh/data/' .. address):format(page_index)
)
end
if success then
result = data or false
else
result = false
end
if result then
if variety == "nan" and entry_creation then
result = gsub(result, "%-á%-", "-仔-")
result = gsub(result, "%-á/", "-仔/")
result = gsub(result, "%-á$", "-仔")
result = gsub(result, "^(.+)%-%1%-%1$", "(%1)")
result = gsub(result, "^(.+)%-%1%-%1()", "(%1)%2")
result = gsub(result, "()(.+)%-%1%-%1$", "%1(%2)")
result = gsub(result, "()(.+)%-%1%-%1()", "%1(%2)%3")
end
end
return result
end
function M.nan_for_bot()
local text = mw.title.getCurrentTitle().text
local result = M.check_pron(text, 'nan')
if result then
return '\n|mn=' .. result
else
return
end
end
function M.der(frame)
local params = {
= { list = true },
= { type = "boolean" },
= {},
= { type = "boolean" },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local pagename = mw.title.getCurrentTitle().text
local result = {}
local fold = args
local title = args and " (<i>" .. args .. "</i>)" or ""
local saurus = mw.title.getCurrentTitle().nsText == "Thesaurus" and true or false
local no_transcript = args
for _, word in ipairs(args) do
table.insert(result, word and M.link(frame, nil, mw.text.split(word, ":"), pagename, no_transcript))
end
return
require("Module:columns").create_table(
(len(pagename) > 1 and 2 or 3),
result,
1,
"#F5F5FF",
(((#result > 72 or fold) and not saurus) and true or false),
"Derived terms",
"Derived terms from " .. format_Chinese_text(pagename) .. title,
math.floor(80 / (len(pagename) > 1 and 2 or 3)),
"* ",
nil
)
end
local lang_abbrev = {
= 'Mandarin',
= 'Cantonese', = 'Gan', = 'Hakka', = 'Jin',
= 'Min Dong', = 'Min Nan', = 'Teochew',
= 'Wu', = 'Xiang',
}
function M.cls(frame)
local args = frame:getParent().args
local result, categories = {}, {}
local m_zh_cat = require("Module:zh-cat")
local space = '<span style="padding-left:4px; padding-right:4px"> </span>'
for _, combination in ipairs(args) do
local part = mw.text.split(combination, ":")
local note
if #part == 2 then
local dialect = { "" }
local function annotate(main_text, annotation)
return "<span style=\"border-bottom: 1px dotted #000; cursor:help\" " ..
"title=\"" .. annotation .. "\"><i>" .. main_text .. "</i></span>"
end
for variety in mw.text.gsplit(part, ",") do
table.insert(dialect, annotate(variety, lang_abbrev))
end
note = table.concat(dialect, " ")
else
note = false
end
table.insert(result, M.link(frame, nil, { part or part, tr = "-" }, pagename) .. -- pagename is undefined!
(note or ""))
table.insert(categories, m_zh_cat.categorize("Classifier:" .. (part or part)))
end
return "<span style=\"padding-left:15px; font-size:80%\"><span style=\"background:#EDFFFF\">(''Classifier'': " ..
table.concat(result, ";" .. space) .. ")</span></span>" ..
(mw.title.getCurrentTitle().nsText == "" and table.concat(categories) or "")
end
function M.newDer(frame)
local title = mw.title.getCurrentTitle().subpageText
local prefix = "Module:zh/data/wordlist/"
local args = frame:getParent().args
local limit = args and tonumber(args) or false
local char_pronunciation = args or false
local fold = args or false
local hide_pron = args or false
local result = {}
for _, arg in ipairs(args) do
table.insert(result, arg)
end
local i = 1
while i < 4 do
local wordlist = require(prefix .. tostring(i))
for word, pronunciation in pairs(wordlist) do
if match(word, title) and word ~= title and not (len(title) == 1 and len(word) > (limit or 4)) then
if char_pronunciation then
if mw.text.split(pronunciation, " ") == char_pronunciation then
table.insert(result, word)
end
else
table.insert(result, word)
end
end
end
i = i + 1
end
local hash, res = {}, {}
for _, element in ipairs(result) do
local section = mw.text.split(element, ":")
if not hash then
res = element
hash = true
end
end
return "{{zh-der|" .. (hide_pron and "hide_pron=1|" or "") .. (fold and "fold=1|" or "") .. table.concat(res, "|") .. "}}"
end
function M.create(f,is_erhua)
if not is_erhua then is_erhua = false end
local title = mw.title.getCurrentTitle().text
local params = {
= {}, = {alias_of = "type"},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = "e", allow_holes=true}, = {list = "etym", allow_holes=true}, = {list = "etymology", allow_holes=true}, = {list = true, allow_holes=true},
= {}, = {alias_of = "k"}, = {alias_of = "k"},
= {}, = {alias_of = "kt"}, = {alias_of = "kt"}, = {alias_of = "kt"}, = {alias_of = "kt"}, = {alias_of = "kt"}, = {alias_of = "kt"}, = {alias_of = "kt"},
= {}, = {alias_of = "ke"}, = {alias_of = "ke"}, = {alias_of = "ke"},
= {}, = {alias_of = "v"}, = {alias_of = "v"},
= {}, = {alias_of = "ve"}, = {alias_of = "ve"}, = {alias_of = "ve"}, = {alias_of = "ve"},
= {list = true, allow_holes=true}, = {list = true, allow_holes=true}, = {list = true, allow_holes=true},
= {}, = {alias_of = "e"}, = {alias_of = "e"}, = {alias_of = "e"}, = {alias_of = "e"}, = {alias_of = "e"},
= {list = true}, = {list = true},
= {list = true}, = {list = true},
= {list = true}, = {list = true}, = {list = true}, = {list = true},
= {list = true}, = {list = true}, = {list = true}, = {list = true},
= {}, = {alias_of = "wp"}, = {alias_of = "wp"},
= {list = true}, = {list = true}, = {list = true}, = {list = true}, = {list = true}, = {list = true}, = {list = true},
= {}, = {alias_of = "pic"}, = {alias_of = "pic"}, = {alias_of = "pic"},
= {}, = {alias_of = "piccap"}, = {alias_of = "piccap"}, = {alias_of = "piccap"},
= {}, = {alias_of = "er"},
= {}, = {alias_of = "tl"}, = {alias_of = "tl"}, = {alias_of = "tl"}, = {alias_of = "tl"}, = {alias_of = "tl"},
= {}, = {alias_of = "a"}, = {alias_of = "a"}, = {alias_of = "a"}, = {alias_of = "a"},
= {}, = {alias_of = "alt"}, = {alias_of = "alt"}, = {alias_of = "alt"}, = {alias_of = "alt"},
= {}, = {alias_of = "c"}, = {alias_of = "c"},
= {}, = {alias_of = "mn"}, = {alias_of = "mn"},
= {}, = {alias_of = "w"}, = {alias_of = "w"},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
}
local args = require("Module:parameters").process(f:getParent().args, params)
local comp = args or ""
local pos = {}
local def = {}
for i=1,math.max(args.maxindex/2, args.maxindex, args.maxindex) do
table.insert(pos, args or args or "")
table.insert(def, args or args or "")
end
local function length(array)
return array.maxindex or #array
end
local function expand(arg)
local result = {}
local maximum = 0
for i=1,#arg do if length(arg) > maximum then maximum = length(arg) end end
local current = nil
for i=1,maximum do
current = nil
for j=1,#arg do
if current then
break
else
current = arg
end
end
current = current or ""
table.insert(result, current)
end
return result
end
local function fetch_all(arg)
local result = {}
for i=1,#arg do
for j=1,#arg do
table.insert(result,arg)
end
end
return result
end
local etyms = expand({args, args, args, args})
local ko = args or ""
local kotrans = args or "" -- currently unused
local kodef = args or def or ""
local vi = args or ""
local videf = args or def or ""
local p = expand({args, args, args})
local etym = args or ""
local syn = expand({args, args})
local ant = expand({args, args})
local der = expand({args, args, args, args})
local also = expand({args, args, args, args})
local wp = args or ""
local cat = fetch_all({args, args, args, args, args, args, args})
local pic = args or ""
local piccap = args or ""
local er = args or ""
local tl = args or ""
local audio = args or ""
local alt = args or ""
local m_s = args or ""
local c = args or ""
local c_t = args or ""
local mn = args or ""
local mn_t = args or ""
local w = args or ""
local m = args or ""
local h = args or ""
local g = args or ""
local j = args or ""
local x = args or ""
local md = args or ""
local mc = args or ""
local oc = args or ""
local ts = args or ""
local gloss = args or ""
local lit = args or ""
local t2 = args or ""
local text = ''
if not pos or pos == '' then pos = 'n' end
for i=1,#pos do pos = checkpos(pos) end
text = (text .. '==Chinese==\n')
if M.ts_determ(title) == 'simp' and ts ~= "trad" then
return text .. '{{zh-see|' .. M.st(title) .. ('}}'):format(mw.title.getCurrentTitle().text)
end
length = len(title)
local noerhua = sub(title,1,length-1) -- currently unused
local erhua = sub(title,length,length) -- currently unused
text = text .. (is_erhua and M.hzbox_er(title) or M.hzbox(title,comp,table.concat(etyms,'|'),alt,gloss,lit,t2))
if wp ~= '' then text = (text .. '\n{{zh-wp' .. (wp ~= 'y' and '|' .. wp or '') .. '}}') end
if pic ~= '' then text = (text .. '\n]') end
if is_erhua then
text = (text .. '===Pronunciation===\n{{zh-pron\n\|m=' .. M.pytemp_er(title,comp,pos,p) .. 'r\n|cat=' .. table.concat(pos,',') .. '\n}}\n\n')
else
text = (text .. '\n\n')
if etym ~= '' then text = (text .. '===Etymology===\n' .. etym .. '\n\n') end
text = (text .. '===Pronunciation===\n{{zh-pron')
if m ~= '-' then
if m ~= '' then
local m_pron = m
text = (text .. '\n|m=' .. m_pron)
else
local m_pron = gsub(M.pytemp(title,comp,pos,p), ',', ', ')
text = (text .. '\n|m=' .. m_pron)
if er ~= '' then text = (text .. ',er=' .. er) end
if tl ~= '' then text = (text .. ',tl=y') end
end
end
if length == 1 or m_s ~= '' then text = (text .. '\n|m-s=' .. (m_s or "")) end
if c == '' then c = M.check_pron(title, 'yue', length) or '' end
if length == 1 or (c ~= '' and c ~= '-') then text = (text .. '\n|c=' .. (c or "")) end
if length == 1 or c_t ~= '' then text = (text .. '\n|c-t=' .. (c_t or "")) end
if length == 1 or g ~= '' then text = (text .. '\n|g=' .. (g or "")) end
if h == '' then h = M.check_pron(title, 'hak') or '' end
if length == 1 or (h ~= '' and h ~= '-') then text = (text .. '\n|h=' .. (h and ("pfs=" .. h) or "")) end
if length == 1 or j ~= '' then text = (text .. '\n|j=' .. (j or "")) end
if length == 1 or md ~= '' then text = (text .. '\n|md=' .. (md or "")) end
if mn == '' then mn = M.check_pron(title, 'nan', nil, true) or '' end
if length == 1 or (mn ~= '' and mn ~= '-') then text = (text .. '\n|mn=' .. (mn or "")) end
if length == 1 or mn_t ~= '' then text = (text .. '\n|mn-t=' .. (mn_t or "")) end
if length == 1 or w ~= '' then text = (text .. '\n|w=' .. (w or "")) end
if length == 1 or x ~= '' then text = (text .. '\n|x=' .. (x or "")) end
if audio ~= '' then text = (text .. '\n|ma=') if audio ~= 'y' then text = (text .. audio) else text = (text .. 'y') end end
if length == 1 or mc ~= '' then text = (text .. '\n|mc=' .. (mc ~= "" and mc or 'y')) end
if length == 1 or oc ~= '' then text = (text .. '\n|oc=' .. (oc ~= "" and oc or 'y')) end
text = (text .. '\n|cat=' .. table.concat(pos,',') .. '\n}}\n\n')
end
text = (text .. '===' .. (length == 1 and "Definitions" or M.postitle(pos)) .. '===\n')
text = (text .. '{{zh-' .. (length == 1 and "hanzi" or M.poshead(pos)) .. '}}\n\n')
if is_erhua then
text = text .. '# {{context|Mandarin|lang=zh}} {{erhua form'
if def and def ~= '' then text = text .. '|' .. def end
text = text .. '}}'
else
text = (text .. '# ' .. ((def and def ~= "") and def or "{{rfdef|lang=zh}}"))
end
if syn then
if match(syn, "^dial") then
text = text .. "\n\n====Synonyms====\n{{zh-" .. syn .. "}}"
else
text = M.semantics(text,'Synonyms',syn)
end
end
text = M.semantics(text,'Antonyms',ant)
text = M.semantics(text,'Derived terms',der)
for i=2,#pos do
text = text .. '\n\n===' .. M.postitle(pos) .. '===\n'
text = text .. '{{zh-' .. M.poshead(pos) .. '}}\n\n'
if is_erhua then
text = text .. '# {{context|Mandarin|lang=zh}} {{erhua form'
if def ~= '' then text = text .. '|' .. def end
text = text .. '}}'
else
text = text .. '# ' .. def
end
end
if #also > 0 then
text = (text .. '\n\n====See also====')
for i=1,#also do
text = (text .. '\n* {{zh-l|' .. also .. '}}')
end
end
if #cat > 0 then text = (text .. '\n\n{{zh-cat|' .. table.concat(cat,'|') .. '}}') end
if ko ~= '' then
text = text .. '\n\n----\n\n==Korean==\n{{ko-hanjatab}}\n\n===Noun===\n{{ko-noun|hj|hangeul=' .. ko .. '}}\n\n# {{hanja form of|' .. ko .. '|' .. kodef .. '}}'
end
if vi ~= '' then
text = text .. '\n\n----\n\n==Vietnamese==\n{{vi-hantutab}}\n\n===' .. M.postitle(pos) .. '===\n{{vi-hantu}}\n\n# {{han tu form of|' .. vi .. '|' .. videf .. '}}'
end
return text
end
function M.wikipedia(frame)
local args = frame:getParent().args
local title = mw.title.getCurrentTitle().text
local wp_data = {
= { "Written Standard Chinese<sup>]</sup>", "Hani", "zh" },
= { "Min Dong", "cdo" },
= { "Gan", "zh" },
= { "Hakka", "hak" },
= { "Classical", "zh" },
= { "Min Nan", "nan" },
= { "Wu", "zh" },
= { "Cantonese", "zh" },
= { "English", "en" },
}
args = args and args or { "zh" }
local result = { '<div class="sister-wikipedia sister-project noprint floatright" style="border: 1px solid #aaa; font-size: 90%; background: #f9f9f9; width: 250px; padding: 4px; text-align: left;"><div style="float: left;">]</div><div style="margin-left: 40px;">] has ' ..
(args and "articles" or "an article") .. ' on:' }
for _, arg in ipairs(args) do
local part = mw.text.split(arg, ":")
local lang_data = wp_data] or { nil, "Hani", "zh" }
local annotation = lang_data or false
if part == "zh" and not args then
annotation = false
elseif annotation then
annotation = " <span style=\"font-size\:80%\">(" .. annotation .. ")</span>"
end
local script = match(part or title, "") and "Hani" or "Latn"
table.insert(result, '<div style="margin-left: 10px;">• <b class="' .. (gsub(script, "Latn", (len(part or title) < 15 and "Latn\" style=\"font-size:120%" or "Latn"))) .. '" lang="' .. lang_data .. '"> .. ':' .. (part or title) .. '|' .. (part or title) .. ']]</b>' .. (annotation or "") .. '</div>')
end
table.insert(result, '</div></div>')
return table.concat(result)
end
function M.saurus(frame)
local args = frame:getParent().args
local word = args or mw.title.getCurrentTitle().text
local content = mw.title.new("Thesaurus:" .. word):getContent()
local template = match(content, "{{zh%-list|(+)}}")
if template and template ~= "" then
local set = {}
for item in mw.text.gsplit(template, "|") do
table.insert(set, item)
end
return '<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[' ..
tostring(mw.uri.fullUrl("Thesaurus:" .. word, { = "edit" })) ..
' edit]</span></div></sup>' .. mw.getCurrentFrame():expandTemplate{ title = "Template:zh-list", args = set }
else
return ""
end
end
function M.div(frame)
local args = frame:getParent().args
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("zh")
local pagename = mw.title.getCurrentTitle().text
local i, result = 1, ""
local function add_link(pagename, description)
local target_page = mw.title.new(pagename .. description)
if target_page.exists and not target_page.isRedirect then
return format_Chinese_text(m_links.language_link({ term = pagename .. description, alt = "~" .. description, lang = lang }))
else
return format_Chinese_text("~" .. m_links.language_link({ term = description, lang = lang }))
end
end
while args do
if i ~= 1 then result = result .. "''separator ''" end
result = result .. add_link(pagename, args)
if i == 1 and args then
local j = 2
result = result .. "'', formerly ''" .. add_link(pagename, args)
while args do
result = result .. "'', ''" .. add_link(pagename, args)
j = j + 1
end
end
i = i + 1
end
result = gsub(result, "separator", match(result, "formerly") and ";" or ",")
return format_Chinese_text("(") .. result .. format_Chinese_text(")")
end
function M.etym_short(frame)
local args = frame:getParent().args
local pinyin = args or false
local gloss = args or false
local nocap = args or false
local notext = args or false
local comb = args or false
local t, s, tr, anno, word = {}, {}, {}, {}, {}
local start = (nocap and "s" or "S") .. "hort for "
local cat = require("Module:zh-cat").categorize("short")
if comb then
for _, arg in ipairs(args) do
table.insert(word, M.link(frame, nil, { arg }))
end
return start .. table.concat(word, " + ") .. cat
end
for _, arg in ipairs(args) do
table.insert(t, "]")
table.insert(s, "]")
if not pinyin then table.insert(tr, M.extract_pron(arg, "m")) end
end
local trad = format_Chinese_text(table.concat(t))
local simp = format_Chinese_text(table.concat(s))
pinyin = pinyin ~= "-" and pinyin or (#tr == #t and table.concat(tr, " ") or false)
table.insert(anno, format_rom(pinyin))
table.insert(anno, format_gloss(gloss))
return (notext and "" or start) .. trad .. (trad ~= simp and "/" .. simp or "") ..
((pinyin or gloss) and " (" .. table.concat(anno, ", ") .. ")" or "") .. cat
end
return M