Module:head/languages: Difference between revisions

Jump to navigation Jump to search
ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
Line 7: Line 7:
[1] = {list = true},
[1] = {list = true},
["head"] = {},
["head"] = {},
["stem"] = {list = true, allow_holes = true},
["label"] = {list = true},
["label"] = {list = true},
["noauto"] = {type = "boolean"},
}
}


function export.get_args(args, params, inflection_params)
function export.attempt_auto_inflection(inflection_param, args, term)
if args["noauto"] then return nil end
if not inflection_param.auto then return nil end
local i = 1
local auto = mw.ustring.gsub(inflection_param.auto, "$0", term)
while i < (p["stem"]["maxindex"] + 1) do
if p["stem"][i] then
auto = mw.ustring.gsub(auto, "$" .. i .. "%??", p["stem"][i])
end
i = i + 1
end
auto = mw.ustring.gsub(auto, "$%d%?", term)
return auto
end
 
function export.get_args(args, params, inflection_params, term)
if inflection_params then
if inflection_params then
for _, v in ipairs(inflection_params) do
for _, v in ipairs(inflection_params) do
Line 21: Line 38:
for _, v in ipairs(inflection_params) do
for _, v in ipairs(inflection_params) do
local inflection = p[v.param]
local inflection = p[v.param]
if not inflection then
inflection = export.attempt_auto_inflection(v, p, term)
end
inflection["label"] = v.label
inflection["label"] = v.label
inflection["glossary"] = v.glossary
inflection["glossary"] = v.glossary
Line 35: Line 55:
function export.show(frame)
function export.show(frame)
local language = m_languages.get_by_code(frame.args[1])
local language = m_languages.get_by_code(frame.args[1])
local term = export.get_term()
local pos = frame.args[2]
local pos = frame.args[2]
local inflection_params = mw.loadData("Module:head/languages/" .. language.code)
local inflection_params = mw.loadData("Module:head/languages/" .. language.code)
local args, inflections = export.get_args(frame:getParent().args, default_params, inflection_params[pos])
local args, inflections = export.get_args(frame:getParent().args, default_params, inflection_params[pos], term)
return m_head.full_head{
return m_head.full_head{
term = mw.title.getCurrentTitle().text,
term = term,
head = args["head"],
head = args["head"],
language = language,
language = language,

Navigation menu