Module:mg-noun: Difference between revisions

No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 16: Line 16:
local NAMESPACE = mw.title.getCurrentTitle().nsText
local NAMESPACE = mw.title.getCurrentTitle().nsText


local genders = {["m"] = "masculine", ["f"] = "feminine"}
local genders = {["m"] = "masculine", ["f"] = "feminine", ["?"] = ""}


local function detect_decl(word)
local function detect_decl(word)
if word:match("[aeorá]$") then
if word:match("[aeoá]$") then
return sub(word, -1, -1) -- last letter
return sub(word, -1, -1) -- last letter
elseif word:match("n$") then
elseif word:match("n$") then
return "nt"
return "nt"
else
else
return "consonant"
return "cons"
end
end
end
end
Line 37: Line 37:
local word = NAMESPACE == "Template" and "mazer" or parent_args["word"] or PAGENAME
local word = NAMESPACE == "Template" and "mazer" or parent_args["word"] or PAGENAME
local args = {}
local args = {}
local decl_type = parent_args[2] or parent_args["decl"] or detect_decl(word)
local decl_type = NAMESPACE == "Template" and "r" or parent_args[2] or parent_args["decl"] or detect_decl(word)
if g ~= "m" and g ~= "f" then error("Unknown gender: it must be either ‘m’ or ‘f’") end
if g ~= "m" and g ~= "f" and g ~= "?" then error("Unknown gender: it must be either ‘m’ or ‘f’") end
if not m_data[word] then
if not m_data[word] then
Line 74: Line 74:
-- make the table
-- make the table
return make_table(data)
return make_table(data, parent_args)
end
end


function make_table(data)
function make_table(data, args)


local function show_form(form)
local function show_form(form)
Line 124: Line 124:
for _, case in ipairs(cases) do
for _, case in ipairs(cases) do
local case_short = sub(case, 1, 2)
local case_short = sub(case, 1, 2)
local form_s = args[case_short .. '_s'] and {args[case_short .. '_s']} or data.forms[case_short .. '_s'] or nil
local form_p = args[case_short .. '_p'] and {args[case_short .. '_p']} or data.forms[case_short .. '_p'] or nil
table.insert(ret, '|- \n! ' .. case .. '\n')
table.insert(ret, '|- \n! ' .. case .. '\n')
table.insert(ret, '| ' .. link(show_form(data.forms[case_short .. '_s'])) .. '\n')
table.insert(ret, '| ' .. link(show_form(form_s)) .. '\n')
if not data.nopl then
if not data.nopl then
table.insert(ret, '| ' .. link(show_form(data.forms[case_short .. '_p'])) .. '\n')
table.insert(ret, '| ' .. link(show_form(form_p)) .. '\n')
end
end
end
end