Module:head/templates: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) mNo edit summary Tag: Reverted |
TheNightAvl (talk | contribs) No edit summary Tag: Manual revert |
||
(18 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
[3] = {list = true}, | [3] = {list = true}, | ||
["g"] = {list = true}, | ["g"] = {list = true}, | ||
["label"] = {list = true}, | |||
["head"] = {}, | ["head"] = {}, | ||
["nocat"] = {type = "boolean"}, | ["nocat"] = {type = "boolean"}, | ||
Line 45: | Line 46: | ||
local p = m_parameters.process(args, params) | local p = m_parameters.process(args, params) | ||
local language = m_languages.get_by_code(p[1]) | local language = m_languages.get_by_code(p[1]) | ||
local term = mw.title.getCurrentTitle(). | local term = mw.title.getCurrentTitle().text | ||
if language.proto then | if language.proto then | ||
term = mw.ustring.gsub(term, "^[^/]+/", "") | term = mw.ustring.gsub(term, "^[^/]+/", "") | ||
Line 56: | Line 57: | ||
head = p["head"], | head = p["head"], | ||
nocat = p["nocat"], | nocat = p["nocat"], | ||
labels = p["label"], | |||
inflections = get_inflections(p[3]), | inflections = get_inflections(p[3]), | ||
} | } |
Latest revision as of 01:18, 28 April 2024
Documentation for this module may be created at Module:head/templates/documentation
local export = {}
local m_head = require("Module:head")
local m_languages = require("Module:languages")
local m_parameters = require("Module:parameters")
local params = {
[1] = {required = true},
[2] = {required = true},
[3] = {list = true},
["g"] = {list = true},
["label"] = {list = true},
["head"] = {},
["nocat"] = {type = "boolean"},
}
local function get_inflections(list)
local inflections = {}
local i = 1
while list[i] do
local inflection = {["label"] = list[i]}
if not list[i+1] then
error("unexpected end of inflection forms")
elseif list[i+1] == "or" then
error("unexpected 'or' keyword in label slot of inflection forms")
end
i = i + 1
while list[i] do
table.insert(inflection, list[i])
if list[i+1] and list[i+1] == "or" then
if not list[i+2] then
error("unexpected end of inflection forms")
end
i = i + 2
else
i = i + 1
break
end
end
table.insert(inflections, inflection)
end
return inflections
end
local function get_data(args)
local p = m_parameters.process(args, params)
local language = m_languages.get_by_code(p[1])
local term = mw.title.getCurrentTitle().text
if language.proto then
term = mw.ustring.gsub(term, "^[^/]+/", "")
end
return {
term = term,
language = language,
pos = p[2],
genders = p["g"],
head = p["head"],
nocat = p["nocat"],
labels = p["label"],
inflections = get_inflections(p[3]),
}
end
function export.show(frame)
return m_head.full_head(get_data(frame:getParent().args))
end
return export