Module:Zh
Appearance
Documentation for this module may be created at Module:Zh/doc
local p = {
fr = {
args = {}
}
}
local t1st = {
["228 Incident"] = true,
["Bao'an County"] = true,
["Chinese calendar"] = true,
["Lippo Centre, Hong Kong"] = true,
["Republic of China"] = true,
["Republic of China at the 1924 Summer Olympics"] = true,
["Taiwan"] = true,
["Taiwan (island)"] = true,
["Taiwan Province"] = true,
["Wei Boyang"] = true,
}
function p.getParent()
return p.fr
end
function p.Zh(frame)
-- Get the args. I don't know if there's a preferred way to do it but this works
local args = {}
local pframe = frame:getParent()
for k, v in pframe:argumentPairs() do
args[k] = v
end
local body = "" -- the output string
-- Get all the parameters into vars, or use "" if none is supplied (avoids seperate test for empty strings)
local c = args["c"] or ""
local s = args["s"] or ""
local t = args["t"] or ""
local hp = args["p"] or args["hp"] or ""
local tp = args["tp"] or ""
local w = args["w"] or ""
local j = args["j"] or ""
local cy = args["cy"] or ""
local poj = args["poj"] or ""
local zhu = args["zhu"] or ""
local l = args["l"] or ""
local no = args["links"] == "no"
local title = mw.title.getCurrentTitle()
local t1 = args["first"] == "t" or t1st[title.text]
if (c > "" or (s > "" and s == t)) then -- if simplified and traditional the same they are merged into Chinese.
c = c or s
c = p.lang("zh", c)
if (no) then -- handle "links=no"
body = body .. "Chinese: " .. c .. "; "
else
body = body .. "[[Chinese language|Chinese]]: " .. c .. "; "
end
end
-- temporaries, used for reordering
local sOut, tOut = "", ""
if (s ~= t) then -- if they are the same should under Chinese
if (s > "") then
s = p.lang("zh-Hans", s)
if (t > "") then -- only display full name if traditional also appears
name = "simplified Chinese"
else
name = "Chinese"
end
if (no) then -- handle "links=no"
sOut = name .. ": " .. s .. "; "
else
sOut = "[[Simplified Chinese character|" .. name .."]]: " .. s .. "; "
end
end
if (t > "") then
t = p.lang("zh-Hant", t)
if (s > "") then -- only display full name if simplified also appears
name = "traditional Chinese"
else
name = "Chinese"
end
if (no) then -- handle "links=no"
tOut = name .. ":" .. t .. "; "
else
tOut = "[[Traditional Chinese character|" .. name .."]]: " .. t .. "; "
end
end
if (t1) then -- order based on "first=t"
body = body .. tOut .. sOut
else
body = body .. sOut .. tOut
end
end
sOut = ""
tOut = ""
if (hp > "") then
if (tp > "") then -- only display full name if Tongyo pinyin also appears
name = "Hanyu Pinyin"
else
name = "pinyin"
end
if (no) then -- handle "links=no"
sOut = name .. ": ''" .. hp .. "''; "
else
sOut = "[[pinyin|" .. name .. "]]: ''" .. hp .. "''; "
end
end
if (tp > "") then
if (no) then -- handle "links=no"
tOut = "Tongyong Pinyin: " .. tp .. "; "
else
tOut = "[[Tongyong Pinyin]]: " .. tp .. "; "
end
end
if (t1) then -- order based on "first=t"
body = body .. tOut .. sOut
else
body = body .. sOut .. tOut
end
if (w > "") then
if (no) then -- handle "links=no"
body = body .. "Wade-Giles: " .. w .. "; "
else
body = body .. "[[Wade-Giles]]: " .. w .. "; "
end
end
if (j > "") then
if (no) then -- handle "links=no"
body = body .. "Jyutping: " .. j .. "; "
else
body = body .. "[[Jyutping]]: " .. j .. "; "
end
end
if (cy > "") then
if (no) then -- handle "links=no"
body = body .. "Yale: " .. cy .. "; "
else
body = body .. "[[Yale romanization|Yale]]: " .. cy .. "; "
end
end
if (poj > "") then
if (no) then -- handle "links=no"
body = body .. "Pe̍h-ōe-jī: " ..poj .. "; "
else
body = body .. "[[Pe̍h-ōe-jī]]: " ..poj .. "; "
end
end
if (zhu > "") then
if (no) then -- handle "links=no"
body = body .. "Zhuyin Fuhao: " .. zhu .. "; "
else
body = body .. "[[Bopomofo|Zhuyin Fuhao]]: " .. zhu .. "; "
end
end
if (l > "") then
body = body .. "literally: \"" .. l .. "\"; "
end
if (body > "") then -- check for empty string
return string.sub(body, 1, -3) -- chop off final semicolon and space
else --no named parameters; see if there's an unnamed first parameter
c = pframe.args[1] or ""
if (c > "") then -- if there is treat it as Chinese
c = p.lang("zh", c)
if (no) then -- handle "links=no"
return "Chinese: " .. c
else
return "[[Chinese language|Chinese]]: " .. c
end
end
return body
end
end
function p.lang(language, contents)
local displayName = mw.language.fetchLanguageName( language, "en" )
if (displayName ~= "Chinese") then
local langobj = mw.getLanguage("en")
displayName = langobj:lcfirst(displayName)
end
local params = {lang=language}
params["xml:lang"] = language
local cats = "[[Category:Articles containing " .. displayName .. "-language text]]"
return mw.text.tag({name="span",attr=params, content=contents}) .. cats
end
return p