45,333
edits
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local export = {} | |||
local m_u = require('Module:utilities') | |||
local m_data = require('Module:mg-noun/data') | |||
local sub = mw.ustring.sub | local sub = mw.ustring.sub | ||
local find = mw.ustring.find | local find = mw.ustring.find | ||
local match = mw.ustring.match | |||
local gmatch = mw.ustring.gmatch | local gmatch = mw.ustring.gmatch | ||
local gsub = mw.ustring.gsub | |||
local u = mw.ustring.char | |||
local split = mw.text.split | |||
local gsplit = mw.text.gsplit | |||
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ") | local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ") | ||
local NAMESPACE = mw.title.getCurrentTitle().nsText | local NAMESPACE = mw.title.getCurrentTitle().nsText | ||
local | local genders = {["m"] = "masculine", ["f"] = "feminine"} | ||
local function detect_decl(word | local function detect_decl(word) | ||
local last = sub(word, 1, -2) | local last = sub(word, 1, -2) | ||
if | if word:match("[aeor]$") then | ||
return mw.ustring.upper(last) | |||
return mw.ustring.upper(last) | |||
elseif word:match("n$") then | elseif word:match("n$") then | ||
return "participle" | return "participle" | ||
end | end | ||
end | end | ||
Line 31: | Line 32: | ||
local parent_args = frame:getParent().args | local parent_args = frame:getParent().args | ||
local numbers = | local numbers = {} | ||
local decl = {} | local decl = {} | ||
local | local g = NAMESPACE == "Template" and "f" or parent_args["g"] | ||
local word = NAMESPACE == "Template" and "mazer" or parent_args["word"] or PAGENAME | |||
local args = {} | local args = {} | ||
local decl_type = "" | local decl_type = parent_args[1] or parent_args["decl"] or detect_decl(word) | ||
if g ~= "m" and g ~= "f" then error("Unknown gender: it must be either ‘i’ or ‘a’") end | |||
if not m_data[word] then | if not m_data[word] then | ||
if not decl_type then | |||
error("Unknown declension '" .. decl_type .. "'") | error("Unknown declension '" .. decl_type .. "'") | ||
end | end | ||
args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true) | args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true) | ||
Line 66: | Line 58: | ||
local data = {forms = {}, categories = {}} | local data = {forms = {}, categories = {}} | ||
data.head = parent_args["head"] or | data.head = parent_args["head"] or word | ||
data.proper = parent_args["proper"] and true or false | data.proper = parent_args["proper"] and true or false | ||
data.nocat = parent_args["nocat"] and true or false | data.nocat = parent_args["nocat"] and true or false | ||
data. | data.g = genders[g] | ||
data. | data.decl_type = decl_type | ||
data.pos = parent_args["pos"] or "nouns" | |||
-- Generate the forms | -- Generate the forms | ||
if | if m_data[word] then | ||
m_data[word](parent_args, data) | m_data[word](parent_args, data) | ||
else | else | ||
m_data[decl_type](args, data) | m_data[decl_type](args, data) | ||
end | end | ||
-- | -- make the table | ||
return make_table(data) | return make_table(data) | ||
end | end | ||
Line 142: | Line 135: | ||
<div class="mw-collapsible-content" style="font-size: 100%;"> | <div class="mw-collapsible-content" style="font-size: 100%;"> | ||
]=] | ]=] | ||
local wikicode = [=[ | local wikicode = [=[ | ||
{| class="bluetable" border="1px solid #000000" style="border-collapse:collapse; background:#fafafa; text-align:center; width:100%" | {| class="bluetable" border="1px solid #000000" style="border-collapse:collapse; background:#fafafa; text-align:center; width:100%" | ||
|- | |- | ||
Line 152: | Line 144: | ||
]=] .. make_cases(data) .. [=[ | ]=] .. make_cases(data) .. [=[ | ||
|}</div></div>]=] | |}</div></div>]=] | ||
return gsub(navframe .. wikicode, "{{{([a-z0-9_]+)}}}", repl) | |||
.. (not data.nocat and m_u.format_categories(data.categories, lang) or "") | |||
return gsub(navframe .. | |||
.. (not data.nocat and | |||
end | end | ||
return export | return export |