มอดูล:Lang-zh และ มอดูล:Lang-zh/sandbox: ความแตกต่างระหว่างหน้า
หน้าตา
(ผลต่างระหว่างหน้า)
เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
ไม่มีความย่อการแก้ไข |
thai |
||
บรรทัด 1: | บรรทัด 1: | ||
require(' |
require('strict') |
||
local p = {} |
local p = {} |
||
บรรทัด 18: | บรรทัด 18: | ||
-- the labels for each part |
-- the labels for each part |
||
local labels = { |
local labels = { |
||
⚫ | |||
["c"] = "จีน", |
["c"] = "จีน", |
||
["s"] = "จีนตัวย่อ", |
["s"] = "จีนตัวย่อ", |
||
บรรทัด 27: | บรรทัด 28: | ||
["cy"] = "เยลกวางตุ้ง", |
["cy"] = "เยลกวางตุ้ง", |
||
["sl"] = "ซิดนีย์ เหล่า", |
["sl"] = "ซิดนีย์ เหล่า", |
||
["poj"] = " |
["poj"] = "เป่อ่วยจี", |
||
["zhu"] = "จู้อิน", |
["zhu"] = "จู้อิน", |
||
["l"] = "แปลตรงตัว", |
["l"] = "แปลตรงตัว", |
||
บรรทัด 43: | บรรทัด 44: | ||
["cy"] = "Yale romanization of Cantonese", |
["cy"] = "Yale romanization of Cantonese", |
||
["sl"] = "Sidney Lau romanisation", |
["sl"] = "Sidney Lau romanisation", |
||
["poj"] = " |
["poj"] = "เป่อ่วยจี", |
||
["zhu"] = "จู้อิน", |
["zhu"] = "จู้อิน", |
||
["l"] = "การแปลตรงตัว", |
["l"] = "การแปลตรงตัว", |
||
["tr"] = "การแปล", |
|||
} |
} |
||
บรรทัด 77: | บรรทัด 79: | ||
["sl"] = true, |
["sl"] = true, |
||
} |
} |
||
-- Categories for different kinds of Chinese text |
-- Categories for different kinds of Chinese text |
||
local cats = { |
local cats = { |
||
บรรทัด 93: | บรรทัด 96: | ||
function p._Zh(args) |
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 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 |
|||
⚫ | |||
if args["out"] then |
|||
out = args["out"] |
|||
usebrackets = 1 |
|||
end |
|||
local t1 = false -- whether traditional Chinese characters go first |
local t1 = false -- whether traditional Chinese characters go first |
||
local j1 = false -- whether Cantonese Romanisations go first |
local j1 = false -- whether Cantonese Romanisations go first |
||
บรรทัด 116: | บรรทัด 130: | ||
-- based on setting/preference specify order |
-- based on setting/preference specify order |
||
local orderlist = {"c", "s", "t", "p", "tp", "w", "j", "cy", "sl", "poj", "zhu", "l"} |
local orderlist = {"c", "s", "t", "p", "tp", "w", "j", "cy", "sl", "poj", "zhu", "l", "tr"} |
||
if (t1) then |
if (t1) then |
||
orderlist[2] = "t" |
orderlist[2] = "t" |
||
บรรทัด 129: | บรรทัด 143: | ||
orderlist[9] = "w" |
orderlist[9] = "w" |
||
end |
end |
||
⚫ | |||
-- rename rules. Rules to change parameters and labels based on other parameters |
-- rename rules. Rules to change parameters and labels based on other parameters |
||
if args["hp"] then |
if args["hp"] then |
||
บรรทัด 145: | บรรทัด 159: | ||
args["s"] = nil |
args["s"] = nil |
||
args["t"] = nil |
args["t"] = nil |
||
if out == "s" or out == "t" then |
|||
out = "c" |
|||
end |
|||
elseif (not (args["s"] and args["t"])) then |
elseif (not (args["s"] and args["t"])) then |
||
-- use short label if only one of simplified and traditional |
-- use short label if only one of simplified and traditional |
||
บรรทัด 150: | บรรทัด 167: | ||
labels["t"] = labels["c"] |
labels["t"] = labels["c"] |
||
end |
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 |
local body = "" -- the output string |
||
บรรทัด 159: | บรรทัด 187: | ||
for i, part in ipairs(orderlist) do |
for i, part in ipairs(orderlist) do |
||
if (args[part]) then |
if (args[part]) then |
||
numargs = numargs + 1 |
|||
-- build label |
-- build label |
||
label = "" |
label = "" |
||
บรรทัด 167: | บรรทัด 196: | ||
capfirst = false |
capfirst = false |
||
end |
end |
||
if (uselinks) then |
if (uselinks and part ~= "l" and part ~= "tr") then |
||
label = "[[" .. wlinks[part] .. "|" .. label .. "]]" |
label = "[[" .. wlinks[part] .. "|" .. label .. "]]" |
||
end |
end |
||
if ( |
if (part == "l" or part == "tr") then |
||
label = label .. " |
label = "<abbr title=\"" .. wlinks[part] .. "\"><small>" .. label .. "</small></abbr>" |
||
else |
else |
||
label = |
label = label .. ":" |
||
end |
end |
||
label = label .. " " |
label = label .. " " |
||
บรรทัด 188: | บรรทัด 217: | ||
val = mw.text.tag({name="span",attrs=params, content=val}) |
val = mw.text.tag({name="span",attrs=params, content=val}) |
||
elseif (part == "l") then |
elseif (part == "l") then |
||
local terms = "" |
|||
-- put individual, potentially comma-separated glosses in single-quotes |
|||
for term in val:gmatch("[^;,]+") do |
|||
term = string.gsub(term, "^([ \"']*)(.*)([ \"']*)$", "%2") |
|||
⚫ | |||
end |
|||
val = string.sub(terms, 1, -3) |
|||
elseif (part == "tr") then |
|||
-- put translations in double quotes |
|||
val = """ .. val .. """ |
val = """ .. val .. """ |
||
end |
end |
||
บรรทัด 201: | บรรทัด 238: | ||
end |
end |
||
-- add both to body |
-- add both to body |
||
if numargs == usebrackets then |
|||
⚫ | |||
-- opening bracket after the `out` term |
|||
body = body .. label .. val .. " (" |
|||
else |
|||
body = body .. label .. val .. "; " |
|||
end |
|||
end |
end |
||
end |
end |
||
if (body > "") then -- check for empty string |
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 .. ")" |
|||
end |
|||
return body |
|||
else --no named parameters; see if there's a first parameter, ignoring its name |
else --no named parameters; see if there's a first parameter, ignoring its name |
||
if (args[1]) then |
if (args[1]) then |
||
บรรทัด 216: | บรรทัด 263: | ||
label = "[[" .. wlinks["c"] .. "|" .. label .. "]]" |
label = "[[" .. wlinks["c"] .. "|" .. label .. "]]" |
||
end |
end |
||
label = label .. "& |
label = label .. ": " |
||
end |
end |
||
-- default to show links and labels as no options given |
-- default to show links and labels as no options given |