Module:Lang-zh: Difference between revisions

Content deleted Content added
Copy from sandbox per request on talk
Publishing User:Northern Moonlight's implementation of new fields to specify locale-specific character glyphs according to the IETF standard
 
(8 intermediate revisions by 3 users not shown)
Line 28:
["sl"] = "Sidney Lau",
["poj"] = "Pe̍h-ōe-jī",
["tl"] = "Tâi-lô",
["zhu"] = "Zhuyin Fuhao",
["l"] = "lit.",
Line 45 ⟶ 46:
["sl"] = "Sidney Lau romanisation",
["poj"] = "Pe̍h-ōe-jī",
["tl"] = "Tâi-uân Lô-má-jī Phing-im Hong-àn",
["zhu"] = "Bopomofo",
["l"] = "Literal translation",
Line 55 ⟶ 57:
["t"] = "zh-Hant",
["s"] = "zh-Hans",
["p"] = "zh-Latn-pinyin",
["tp"] = "zh-Latn-tongyong",
["w"] = "zh-Latn-wadegile",
["j"] = "yue-Latn-jyutping",
Line 62 ⟶ 64:
["sl"] = "yue-Latn",
["poj"] = "nan-Latn",
["tl"] = "nan-Latn-tailo",
["zhu"] = "zh-Bopo",
}
Line 73 ⟶ 76:
["sl"] = true,
["poj"] = true,
["tl"] = true,
}
 
Line 96 ⟶ 100:
function p._Zh(args)
if args["link"] then args["links"] = args["link"]; end
if args["label"] then args["labels"] = args["label"]; end
local uselinks = args["links"] ~= "no" -- whether to add links
local uselabels = args["labels"] ~= "no" -- whether to have labels
local capfirst = args["scase"] ~= nil
local out = nil -- which term to put before the brackets
local usebrackets = nil0 -- whether to have bracketed terms
local numargs = 0
local regionalvariant = nil
if args["out"] then
out = args["out"]
usebrackets = true1
end
 
local t1 = false -- whether traditional Chinese characters go first
local j1 = false -- whether Cantonese Romanisations go first
local poj1 = false -- whether Hokkien Romanisations go first
local testChar
if (args["first"]) then
Line 113 ⟶ 124:
if (testChar == "t") then
t1 = true
end
if (testChar == "j") then
j1 = true
end
if v(testChar == out"poj") then
poj1 = true
end
end
end
Line 125 ⟶ 139:
 
-- based on setting/preference specify order
local orderlist = {"c", "s", "t", "p", "tp", "w", "j", "cy", "sl", "poj", "tl", "zhu", "l", "tr"}
if (t1) then
orderlist[2] = "t"
Line 138 ⟶ 152:
orderlist[9] = "w"
end
if out(poj1) then
orderlist[4] = "poj"
for i, v in ipairs (orderlist) do
orderlist[5] = "tl"
if v == out then
table.remove(orderlist,[6] i)= "p"
table.insert(orderlist,[7] 1,= v)"tp"
orderlist[8] = "w"
break
orderlist[9] = "j"
end
orderlist[10] = "cy"
end
orderlist[11] = "sl"
end
 
-- rename rules. Rules to change parameters and labels based on other parameters
if args["hp"] then
Line 155 ⟶ 171:
-- if also Tongyu pinyin use full name for Hanyu pinyin
labels["p"] = "Hanyu Pinyin"
end
-- specify traditional Chinese variants
if args["t_hk"] then
args["t"] = args["t_hk"]
regionalvariant = "HK"
elseif args["t_tw"] then
args["t"] = args["t_tw"]
regionalvariant = "TW"
end
Line 170 ⟶ 195:
labels["t"] = labels["c"]
end
if out then
for i, v in ipairs (orderlist) do -- shift `out` to the beginning of the order list
if v == out then
table.remove(orderlist, i)
table.insert(orderlist, 1, v)
break
end
end
end
 
if (out == "c" and args["s"]) then usebrackets = 2; end
 
local body = "" -- the output string
Line 179 ⟶ 215:
for i, part in ipairs(orderlist) do
if (args[part]) then
numargs = numargs + 1
-- build label
label = ""
Line 187 ⟶ 224:
capfirst = false
end
if (uselinks and part ~= "l" and part ~= "tr") then
label = "[[" .. wlinks[part] .. "|" .. label .. "]]"
end
if (labels[part] ~== "l" or part == "lit.tr") then
label = "<abbr title=\"" .. wlinks[part] .. "\"><small>" .. label .. "&#58;</small></abbr>"
else
label = "<small>" .. label .. "</small>&colon;"
end
label = label .. " "
Line 205 ⟶ 242:
if (ISOlang[part]) then
-- add span for language if needed
params = {["lang"] = ISOlang[part] .. (regionalvariant and "-" .. regionalvariant or "")}
val = mw.text.tag({name="span",attrs=params, content=val})
elseif (part == "l") then
local terms = ""
-- put individual, potentially comma-separated glosses in single- quotes
-- (first strip leading and trailing whitespace and quotes, including bold/italic markup)
for term in val:gmatch("[^;,]+") do
term = stringmw.gsubtext.trim(term, "^([ %s\"']*)(.*)([ \"']*)$", "%2")
terms = terms .. "'&apos;" .. term .. "'&apos;, "
mw.log(term)
terms = terms .. "'" .. term .. "', "
end
val = string.sub(terms, 1, -3)
elseif (part == "tr") then
-- put translations in double quotes
-- (first strip leading and trailing spaces and quotes, including bold/italic markup)
val = "\"" .. val .. "\""
val = mw.text.trim(val, "%s\"'")
val = "\"&quot;" .. val .. "\"&quot;"
end
if (italic[part]) then
Line 230 ⟶ 269:
end
-- add both to body
if inumargs == 1 and usebrackets then
-- opening bracket after the `out` term
body = body .. label .. val .. " ("
else
body = body .. label .. val .. "; "
Line 241 ⟶ 280:
if (body > "") then -- check for empty string
body = string.sub(body, 1, -3) -- chop off final semicolon and space
if out and numargs > usebrackets then
-- closing bracket after the rest of the terms
body = body .. ")&rpar;"
end
return body
Line 255 ⟶ 294:
label = "[[" .. wlinks["c"] .. "|" .. label .. "]]"
end
label = label .. "&#58colon; "
end
-- default to show links and labels as no options given