ผลต่างระหว่างรุ่นของ "มอดูล:nyms"

เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
ZilentFyld (คุย | ส่วนร่วม)
// Edit via Wikiplus
ZilentFyld (คุย | ส่วนร่วม)
ไม่มีความย่อการแก้ไข
บรรทัดที่ 4:
local m_links = require("Module:links")
local m_qual = require("Module:qualifier")
local rsplit = mw.text.split
 
local function wrap_span(text, lang, sc)
return '<span class="' .. sc .. '" lang="' .. lang .. '">' .. text .. '</span>'
end
 
local function get_thesaurus_text(lang, args, maxindex)
local thesaurus
local thesaurus_links = {}
while args[2][maxindex] and args[2][maxindex]:find("^Thesaurus:") do
if args["alt"][maxindex] or args["g"][maxindex] or args["q"][maxindex]
or args["tr"][maxindex] or args["ts"][maxindex] or args["id"][maxindex]
or args["lit"][maxindex] or args["pos"][maxindex] then
error("You cannot use named parameters with Thesaurus links.")
end
local link
local term = args[2][maxindex]:sub(11) -- remove Thesaurus: from beginning
local sc = require("Module:scripts").findBestScript(term, lang):getCode()
local fragment = term:find("#")
if fragment then
link = "[[" .. args[2][maxindex] .. "|Thesaurus:" .. wrap_span(term:sub(1, fragment-1), lang:getCode(), sc) .. "]]"
else
link = "[[" .. args[2][maxindex] .. "|Thesaurus:" .. wrap_span(term, lang:getCode(), sc) .. "]]"
end
table.insert(thesaurus_links, 1, link)
for i maxindex = 1, maxindex do- 1
end
if #thesaurus_links > 0 then
thesaurus = (maxindex == 0 and "''see'' " or "; ''see also'' ")
.. table.concat(thesaurus_links, ", ")
end
return thesaurus or "", maxindex
end
 
function export.nyms(frame)
local list_with_holes = {list = true, allow_holes = true}
local params = {
[1] = {required = true, default = "und"},
[2] = {list = true, allow_holes = true, required = true},
["alt"] = {list = true, allow_holes = true}list_with_holes,
["tr"] = {list = true, allow_holes = true}list_with_holes,
["qts"] = {list = truelist_with_holes, allow_holes = true}
["t"] = list_with_holes,
["id"] = list_with_holes,
["q"] = list_with_holes,
["lit"] = list_with_holes,
["pos"] = list_with_holes,
["g"] = list_with_holes,
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local nym_type = frame.args[1]
local nym_type_class = string.gsub(nym_type, "%s", "-")
local lang = m_languages.getByCode(args[1]) or m_languages.err(args[1], 1)
local maxindex = math.max(args[2].maxindex, args["alt"].maxindex, args["tr"].maxindex)
local thesaurus, link_maxindex = get_thesaurus_text(lang, args, maxindex)
local items = {}
for i = 1, maxindex do
local use_semicolon = false
args[2][i] = m_links.full_link{ lang = lang, term = args[2][i], alt = args["alt"][i], tr = args["tr"][i] }
for i = 1, link_maxindex do
if args[2][i] then
if args[2][i]:find("^Thesaurus:") then
error("A link to Thesaurus must be the last in the list")
end
if args[2][i]:find(",", 1, true) then
use_semicolon = true
end
end
local item = m_links.full_link{
args[2][i] = m_links.full_link{ lang = lang, term = args[2][i], altid = args["altid"][i], tr = args["tr"][i] }
alt = args["alt"][i], tr = args["tr"][i], ts = args["ts"][i],
gloss = args["t"][i], lit = args["lit"][i], pos = args["pos"][i],
genders = args["g"][i] and rsplit(args["g"][i], ",") or {},
}
if args["q"][i] then
args[2][i]item = m_qual.format_qualifier({args[2"q"][i]}) .. " " .. m_qual.format_qualifier({args["q"][i]})item
end
table.insert(items, item)
end
return "<span class=\"nyms " .. frame.args[1]nym_type_class .. "\">''" .. mw.getContentLanguage():ucfirst(frame.args[1]) ..<span class=\"'': defdate\" .. table.concat(args[2], ", >") .. "</span>"
mw.getContentLanguage():ucfirst(nym_type) .. ((#items > 1 or thesaurus ~= "") and "s" or "") ..
":</span> " .. table.concat(items, use_semicolon and "; " or ", ") .. thesaurus .. "</span>"
end