Module:Lang-zh: Difference between revisions

Content deleted Content added
Change to use just 'Chinese:' when only one of simplified or traditional
Add 'no labels' option, simplify associated code; move categories so they won't be at the start or end in edge cases; more comments
Line 66:
function p._Zh(args)
local nouselinks = not (args["links"] == "no") -- whether to add links
local uselabels = not (args["labels"] == "no") -- whether to have labels
local t1 -- whether traditional Chinese characters go first
Line 84 ⟶ 85:
-- rename rules. Rules to change parameters and labels based on other parameters
-- hp an alias for p ([hanyu] pinyin)
if args["hp"] then
-- hp an alias for p ([hanyu] pinyin)
args["p"] = args["hp"]
end
-- if also Tongyu pinyin use full name for Hanyu pinyin
if args["tp"] then
-- if also Tongyu pinyin use full name for Hanyu pinyin
labels["p"] = "Hanyu Pinyin"
end
-- Treat Simplified + Traditional as Chinese if they're the same
if (args["s"] and args["s"] == args["t"]) then
-- Treat Simplifiedsimplified + Traditionaltraditional as Chinese if they're the same
args["c"] = args["s"]
args["s"] = nil
args["t"] = nil
elseif (not (args["s"] and args["t"])) then
-- use short label if only one of simplified and traditional
labels["s"] = labels["c"]
labels["t"] = labels["c"]
Line 109 ⟶ 111:
for i, part in ipairs(orderlist) do
if (args[part]) then
-- build label
local catlabel = ""
if (uselabels) then
catlabel = catslabels[part]
if (uselinks) then
body label = body"[[" .. labelswlink[part] .. cat .. ": |" .. vallabel .. "; ]]"
end
label = label .. ": "
elseend
-- build value
local val = args[part]
local cat = ""
-- if has associated category add it
if (cats[part]) then
-- if has associated category add it
cat = cats[part]
val = cats[part] .. val
end
if (ISOlang[part]) then
-- add span for language if needed
params = {["lang"] = ISOlang[part], ["xml:lang"] = ISOlang[part]}
val = mw.text.tag({name="span",attrs=params, content=val})
elseif (part == "p") then
-- italicise pinyin
val = "''" .. val .. "''"
elseif (part == "l") then
-- put literals in quotes
val = '"' .. val .. '"'
end
-- buildadd thisboth entryto body
ifbody (no)= orbody part.. ==label "l".. thenval
body = body .. labels[part] .. cat .. ": " .. val .. "; "
else
body = body .. "[[" .. wlinks[part] .. "|" .. labels[part] .. "]]" .. cat ..": " .. val .. "; "
end
end
end
Line 136 ⟶ 146:
else --no named parameters; see if there's an unnamed first parameter
if (args[1]) then
c = args[1] -- if there is treat it as Chinese
-- default to show links and labels as no options given
body = args[1]
body = cats["c"] .. body
params = {["lang"] = ISOlang["c"], ["xml:lang"] = ISOlang["c"]}
cbody = mw.text.tag({name="span",attrs=params, content=cbody})
return "[[" .. wlinks["c"] .. "|" .. labels["c"] .. "]]" .. cats["c"] .. ": " .. cbody
end
return ""