Khác biệt giữa bản sửa đổi của “Mô đun:form of/templates”

Nội dung được xóa Nội dung được thêm vào
ChemPro (thảo luận | đóng góp)
Đã lùi lại sửa đổi 2152762 của ChemPro (thảo luận)
Thẻ: Lùi sửa Đã bị lùi lại
ChemPro (thảo luận | đóng góp)
Đã lùi lại sửa đổi 2152764 của ChemPro (thảo luận)
Thẻ: Lùi sửa Đã bị lùi lại
Dòng 1:
local exportinsert = {}table.insert
 
local m_form_of = require("Module:form of")
local m_params = require("Module:parameters")
Hàng 8 ⟶ 7:
local rsplit = mw.text.split
local rgsplit = mw.text.gsplit
 
local export = {}
 
-- Add tracking category for PAGE when called from TEMPLATE. The tracking category linked to is
-- [[TemplateWiktionary:trackingTracking/form-of/TEMPLATE/PAGE]]. If TEMPLATE is omitted, the tracking category is of the form
-- [[TemplateWiktionary:trackingTracking/form-of/PAGE]].
local function track(page, template)
require("Module:debug/track")("form-of/" .. (template and template .. "/" or "") .. page)
Hàng 20 ⟶ 21:
local function extend_list(list, new_items)
for _, item in ipairs(new_items) do
table.insert(list, item)
end
end
 
 
local function get_script(sc, param_for_error)
return sc and require("Module:scripts").getByCode(arg, param_for_error) or nil
end
 
Hàng 83 ⟶ 79:
if param then
if rfind(param, "^[0-9]+$") then
table.insert(numbered_list_params_to_ignore, tonumber(param))
else
table.insert(named_list_params_to_ignore,
"^" .. require("Module:string utilities").pattern_escape(param) .. "[0-9]*$")
end
else
Hàng 122 ⟶ 118:
parent_args = new_parent_args
end
 
local args = m_params.process(parent_args, params, nil, "form of/templates", function_name)
 
Hàng 149 ⟶ 145:
for _, tagspec in ipairs(tagspecs) do
for tag in rgsplit(tagspec, split_regex) do
table.insert(inflection_tags, tag)
end
end
Hàng 169 ⟶ 165:
-- [[Module:links]] expects.
item_dest = "genders",
convert = function(arg, parse_err)
return rsplit(arg, ",")
end,
Hàng 180 ⟶ 176:
pos = {},
sc = {
-- FIXME: [[Module:parse utilities]] should be integrated with [[Module:parameters]], to allow fully automatic error handling.
convert = function(arg, parse_err)
return get_scriptrequire("Module:scripts").getByCode(arg, parse_err) or
parse_err("Parameter \"sc\" should be a valid script code; the value " .. mw.dumpObject(arg) .. " is not valid. See [[WT:LOS]].")
end,
}
Hàng 210 ⟶ 208:
-- expands to multiple terms; easiest not to try and parse the lemma spec as multiple lemmas
retval = {val}
elseif val:find(",%s") or (val:find(",") and val:find("[\\%[<]")) then
-- Comma after whitespace not split; nor are backslash-escaped commas or commas inside of square or
-- angle brackets. If we see any of these, use the more sophisticated algorithm in
-- [[Module:parse utilities]]. Otherwise it's safe to just split on commas directly. This optimization avoids
-- loading [[Module:parse utilities]] unnecessarily.
retval = require(put_module).split_on_comma(val)
else
Hàng 244 ⟶ 246:
end
end
-- If no params for the second or higher term exist, use a simpler param setup to save memory.
params[term_param + 1] = {alias_of = "alt"}
Hàng 255 ⟶ 258:
params["gloss"] = {alias_of = "t"}
params["g"] = {list = true}
params["sc"] = {type = "script"}
for _, param in ipairs(link_params) do
if param ~= "gloss" and param ~= "g" and param ~= "term" then
-- Not "term".
params[param] = {}
for _,i param= in2, ipairs(#link_params) do
end
local param = link_params[i]
params[param] = params[param] or {}
end
end
Hàng 321 ⟶ 326:
]=]
local function get_lemmas_and_categories(iargs, args, term_param, compat, base_lemma_params)
local lang = args[compat and "lang" or 1] or iargs["lang"] or "und"
lang = require("Module:languages").getByCode(lang, compat and "lang" or 1)
 
-- Determine categories for the page, including tracking categories
Hàng 330 ⟶ 334:
if not args["nocat"] then
for _, cat in ipairs(iargs["cat"]) do
table.insert(categories, catlang:getCanonicalName() .. " " .. lang:getCanonicalName()cat)
end
end
for _, cat in ipairs(args["cat"]) do
table.insert(categories, catlang:getCanonicalName() .. " " .. lang:getCanonicalName()cat)
end
 
Hàng 342 ⟶ 346:
-- add tracking category if term is same as page title
if term and mw.title.getCurrentTitle().text == (lang:makeEntryName(term)) then
table.insert(categories, "Forms linking to themselves")
end
-- maybe add tracking category if primary entry doesn't exist (this is an
Hàng 348 ⟶ 352:
if iargs["noprimaryentrycat"] and term and mw.title.getCurrentTitle().nsText == ""
and not mw.title.new(term).exists then
table.insert(categories, iargs["noprimaryentrycat"] .. " " .. lang:getCanonicalName() .. " không" .. mục chínhiargs["noprimaryentrycat"])
end
end
Hàng 381 ⟶ 385:
local sc
if args["sc"] then
lemmas[1].sc = get_script(args["sc"], "sc")
elseif not lemmas[1].sc and iargs["sc"] then
lemmas[1].sc = get_script(iargs["sc"], "sc")
end
 
Hàng 413 ⟶ 417:
local param = base_lemma_param_obj.param
if args[param] then
table.insert(base_lemmas, {
paramobj = base_lemma_param_obj,
lemmas = parse_terms_with_inline_modifiers(param, args[param], lang),
Hàng 472 ⟶ 476:
return {
["term_param"] = {type = "number"},
["lang"] = {}, -- To be used as the default code in params.
["sc"] = {type = "script"},
["cat"] = {list = true},
["ignore"] = {list = true},
Hàng 543 ⟶ 547:
local iparams = get_common_invocation_params()
iparams[1] = {required = true}
local iargs = m_params.process(frame.args, iparams, nil, "form of/templates", "form_of_t")
local parent_args = frame:getParent().args
 
local term_param = iargs["term_param"]
 
local compat = iargs["lang"] or parent_args["lang"]
term_param = term_param or compat and 1 or 2
 
local params = get_common_template_params()
-- Numbered params
params[compat and "lang" or 1] = {
required = not iargs["lang"]},
type = "language",
 
default = iargs["lang"] or "und"
}
local base_lemma_params
if not iargs["nolink"] and not iargs["linktext"] then
Hàng 560 ⟶ 569:
base_lemma_params = add_base_lemma_params(parent_args, iargs, params, compat)
end
 
if next(iargs["cat"]) then
params["nocat"] = {type = "boolean"}
end
 
local ignored_params = {}
 
if iargs["withdot"] then
params["dot"] = {}
Hàng 572 ⟶ 581:
ignored_params["nodot"] = true
end
 
if not iargs["withcap"] then
params["cap"] = {type = "boolean"}
ignored_params["nocap"] = true
end
 
local args = process_parent_args("form-of-t", parent_args, params, iargs["def"],
iargs["ignore"], ignored_params, "form_of_t")
 
local text = args["notext"] and "" or iargs[1]
if args["cap"] or iargs["withcap"] and not args["nocap"] then
text = require("Module:string utilities").ucfirst(text)
end
 
return construct_form_of_text(iargs, args, term_param, compat, base_lemma_params,
function(lemma_data)
Hàng 666 ⟶ 675:
iparams["split_tags"] = {}
 
local iargs = m_params.process(frame.args, iparams, nil, "form of/templates", "tagged_form_of_t")
local parent_args = frame:getParent().args
 
Hàng 676 ⟶ 685:
local params = get_common_template_params()
-- Numbered params
params[compat and "lang" or 1] = {
required = not iargs["lang"]},
type = "language",
default = iargs["lang"] or "und"
}
-- Always included because lang-specific categories may be added
params["nocat"] = {type = "boolean"}
Hàng 757 ⟶ 771:
iparams["split_tags"] = {}
 
local iargs = m_params.process(frame.args, iparams, nil, "form of/templates", "inflection_of_t")
local parent_args = frame:getParent().args
 
Hàng 768 ⟶ 782:
local params = get_common_template_params()
-- Numbered params
params[compat and "lang" or 1] = {
required = not iargs["lang"]},
type = "language",
default = iargs["lang"] or "und"
}
params[tagsind] = {list = true,
-- at least one inflection tag is required unless preinfl or postinfl tags are given
Hàng 828 ⟶ 847:
for _, group in ipairs(groups) do
if #infls > 0 then
table.insert(infls, ";")
end
extend_list(infls, split_preinfl)
Hàng 852 ⟶ 871:
["default"] = {},
}
local iargs = m_params.process(frame.args, iparams, nil, "form of/templates", "normalize_pos")
if not iargs[1] and not iargs["default"] then
error("Either 1= or default= must be given in the invocation args")