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
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
args["p"] = args["hp"]
end
-- if also Tongyu pinyin use full name for Hanyu pinyin▼
if args["tp"] then
labels["p"] = "Hanyu Pinyin"
end
-- Treat Simplified + Traditional as Chinese if they're the same▼
if (args["s"] and args["s"] == args["t"]) then
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
if (uselabels) then
if (uselinks) then
end▼
label = label .. ": "
-- 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
--
▲ body = body .. labels[part] .. cat .. ": " .. val .. "; "
▲ else
▲ end
end
end
Line 136 ⟶ 146:
else --no named parameters; see if there's an unnamed first parameter
if (args[1]) then
-- 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"]}
return "[[" .. wlinks["c"] .. "|" .. labels["c"] .. "]]
end
return ""
|