Module:Lang-zh: Difference between revisions

Content deleted Content added
missed one (all from Special:PrefixIndex/Template:Zh/)
1st attempt at rewrite, uploaded for testing
Line 1:
local p = {}
fr = {
args = {}
}
 
}
 
local t1st = {
["228 Incident"] = true,
Line 18 ⟶ 12:
["Taiwan Province"] = true,
["Wei Boyang"] = true,
}
local labels = {
["c"] = "Chinese",
["s"] = "simplified Chinese",
["t"] = "traditional Chinese",
["h"] = "pinyin",
["tp"] = "Tongyong Pinyin",
["w"] = "Wade–Giles",
["j"] = "Jyutping",
["cy"] = "Cantonese Yale",
["poj"] = "Pe̍h-ōe-jī",
["zhu"] = "Zhuyin Fuhao",
["l"] = "literally",
}
 
local wlinks = {
function p.getParent()
["c"] = "Chinese language",
return p.fr
["s"] = "simplified Chinese characters",
end
["t"] = "traditional Chinese characters",
["h"] = "pinyin",
["tp"] = "Tongyong Pinyin",
["w"] = "Wade–Giles",
["j"] = "Jyutping",
["cy"] = "Yale romanization of Cantonese",
["poj"] = "Pe̍h-ōe-jī",
["zhu"] = "Bopomofo",
}
 
local ISOlang = {
["c"] = "zh",
["t"] = "zh-Hant",
["s"] = "zh-Hans",
}
 
function p.Zh(frame)
local pframe = frame:getParent()
-- Get the args. I don't know if there's a preferred way to do it but this works
local args = {}pframe.args
return p._Zh(args)
local pframe = frame:getParent()
end
for k, v in pframe:argumentPairs() do
args[k] = v
function p._Zh(args)
end
local no = local bodyargs["links"] == "no" -- thewhether to outputadd stringlinks
-- Get all the parameters into vars, or use "" if none is supplied (avoids seperate test for empty strings)
local t1 -- whether traditional Chinese characters go first
local c = args["c"] or ""
if local s = (args["sfirst"] or== ""nil) then
local ttitle = args["t"] or ""mw.title.getCurrentTitle()
t1 = t1st[title.text] == true
local hp = args["p"] or args["hp"] or ""
else
local tp = args["tp"] or ""
local w t1 = args["wfirst"] or== "t"
end
local j = args["j"] or ""
-- based on setting/preference specify order
local cy = args["cy"] or ""
local orderlist
local poj = args["poj"] or ""
if (t1) then
local zhu = args["zhu"] or ""
orderlist = {"c", "t", "s", "h", "tp", "w", "j", "cy", "poj", "zhu", "l"}
local l = args["l"] or ""
else
local no = args["links"] == "no"
orderlist = {"c", "s", "t", "h", "tp", "w", "j", "cy", "poj", "zhu", "l"}
end
local title = mw.title.getCurrentTitle()
local t1 = args["first"] == "t" or t1st[title.text]
-- rewrite rules. Rules to change parameters based on others
 
-- hp an alias for p ([hanyu] pinyin)
if (c > "" or (s > "" and s == t)) then -- if simplified and traditional the same they are merged into Chinese.
if (args["hp"]) then
c = c or s
args["p"] = args["hp"]
c = p.lang("zh", c)
end
if (no) then -- handle "links=no"
-- Treat Simplified + Traditional as Chinese if they're the same
body = body .. "Chinese: " .. c .. "; "
if (args["s"] == args["t"]) then
else
args["c"] = arcs["s"]
body = body .. "[[Chinese language|Chinese]]: " .. c .. "; "
args["s"] = nil
end
args["t"] = nil
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
 
local body = "" -- the output string
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
 
-- go through all possible fields in loop, adding them to the output
if (w > "") then
for i, name in ipairs(orderlist) do
if (no) then -- handle "links=no"
if (args[name]) then
body = body .. "Wade-Giles: " .. w .. "; "
local val = args[name]
else
if (val ~= "") then
body = body .. "[[Wade-Giles]]: " .. w .. "; "
end
if (ISOlang[name]) then
end
val = p.lang(ISOlang[name], val)
if (j > "") then
end
if (no) then -- handle "links=no"
body = body .. "Jyutping: " .. j .. "; "
if (no) or name == "l" then
else
body = body .. "labels[[Jyutping]name] .. ": " .. jval .. "; "
else
end
body = body .. "[[" .. wlinks[name] .. "|" .. labels[name] .. "]]: " .. val .. "; "
end
end
if (cy > "") then
end
if (no) then -- handle "links=no"
end
body = body .. "Yale: " .. cy .. "; "
end
else
body = body .. "[[Yale romanization|Yale]]: " .. cy .. "; "
if (body > "") then -- check for empty string
end
return string.sub(body, 1, -3) -- chop off final semicolon and space
end
else --no named parameters; see if there's an unnamed first parameter
if (poj > "") then
c = args[1]
if (no) then -- handle "links=no"
if (c > "") then -- if there is treat it as Chinese
body = body .. "Pe̍h-ōe-jī: " ..poj .. "; "
c = p.lang("zh", c)
else
if (no) then -- handle "links=no"
body = body .. "[[Pe̍h-ōe-jī]]: " ..poj .. "; "
return "Chinese: " .. c
end
else
end
return "[[Chinese language|Chinese]]: " .. c
if (zhu > "") then
end
if (no) then -- handle "links=no"
end
body = body .. "Zhuyin Fuhao: " .. zhu .. "; "
return body
else
end
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" )
Line 183 ⟶ 127:
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