Content deleted Content added
Single instead of double quotes per MOS:SINGLE -- see talk page |
Publishing User:Northern Moonlight's implementation of new fields to specify locale-specific character glyphs according to the IETF standard |
||
(21 intermediate revisions by 10 users not shown) | |||
Line 1:
require('
local p = {}
Line 28:
["sl"] = "Sidney Lau",
["poj"] = "Pe̍h-ōe-jī",
["tl"] = "Tâi-lô",
["zhu"] = "Zhuyin Fuhao",
["l"] = "
["tr"] = "trans.",
}
Line 44 ⟶ 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",
["tr"] = "Translation",
}
Line 52 ⟶ 57:
["t"] = "zh-Hant",
["s"] = "zh-Hans",
["p"] = "zh-Latn
["tp"] = "zh-Latn-tongyong",
["w"] = "zh-Latn-wadegile",
["j"] = "yue-Latn-jyutping",
["cy"] = "yue-Latn",
["sl"] = "yue-Latn",
["poj"] = "nan-Latn",
["tl"] = "nan-Latn-tailo",
["zhu"] = "zh-Bopo",
}
Line 70 ⟶ 76:
["sl"] = true,
["poj"] = true,
["tl"] = true,
}
Line 76 ⟶ 83:
["sl"] = true,
}
-- Categories for different kinds of Chinese text
local cats = {
Line 92 ⟶ 100:
function p._Zh(args)
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 = 0 -- whether to have bracketed terms
local numargs = 0
local regionalvariant = nil
if args["out"] then
out = args["out"]
usebrackets = 1
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 103 ⟶ 124:
if (testChar == "t") then
t1 = true
if (testChar == "j") then
j1 = true
if (testChar == "poj") then
poj1 = true
end
end
end
Line 115 ⟶ 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 128 ⟶ 152:
orderlist[9] = "w"
end
if (poj1) then
orderlist[4] = "poj"
orderlist[5] = "tl"
orderlist[6] = "p"
orderlist[7] = "tp"
orderlist[8] = "w"
orderlist[9] = "j"
orderlist[10] = "cy"
orderlist[11] = "sl"
end
-- rename rules. Rules to change parameters and labels based on other parameters
if args["hp"] then
Line 137 ⟶ 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 144 ⟶ 187:
args["s"] = nil
args["t"] = nil
if out == "s" or out == "t" then
out = "c"
end
elseif (not (args["s"] and args["t"])) then
-- use short label if only one of simplified and traditional
Line 149 ⟶ 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 158 ⟶ 215:
for i, part in ipairs(orderlist) do
if (args[part]) then
numargs = numargs + 1
-- build label
label = ""
Line 166 ⟶ 224:
capfirst = false
end
if (uselinks and part ~= "l" and part ~= "tr") then
label = "[[" .. wlinks[part] .. "|" .. label .. "]]"
end
label = "<abbr title=\"" .. wlinks[part] .. "\"><small>" .. label .. "</small></abbr>"
else
label = label .. ":"
end
end
-- build value
Line 179 ⟶ 242:
if (ISOlang[part]) then
-- add span for language if needed
params = {["lang"] = ISOlang[part]
val = mw.text.tag({name="span",attrs=params, content=val})
elseif (part == "l") then
-- put individual, potentially comma-separated glosses in single quotes
val = "'" .. val .. '"'▼
-- (first strip leading and trailing whitespace and quotes, including bold/italic markup)
for term in val:gmatch("[^;,]+") do
term = mw.text.trim(term, "%s\"'")
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 = mw.text.trim(val, "%s\"'")
end
if (italic[part]) then
Line 195 ⟶ 269:
end
-- add both to body
if numargs == usebrackets then
▲ body = body .. label .. val .. "; "
-- opening bracket after the `out` term
body = body .. label .. val .. " ("
else
body = body .. label .. val .. "; "
end
end
end
if (body > "") then -- check for empty string
if out and numargs > usebrackets then
-- closing bracket after the rest of the terms
body = body .. ")"
end
return body
else --no named parameters; see if there's a first parameter, ignoring its name
if (args[1]) then
Line 210 ⟶ 294:
label = "[[" .. wlinks["c"] .. "|" .. label .. "]]"
end
label = label .. "&
end
-- default to show links and labels as no options given
Line 219 ⟶ 303:
val = args[1]
end
params = {["
val = mw.text.tag({name="span",attrs=params, content=val})
return label .. val
|