Module:mg-noun: Difference between revisions

No edit summary
No edit summary
 
(13 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)
local last = sub(word, -1, -1)
if word:match("[aeoá]$") then
return sub(word, -1, -1) -- last letter
if word:match("[aeor]$") then
return mw.ustring.upper(last)
elseif word:match("n$") then
elseif word:match("n$") then
return "participle"
return "nt"
else
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 ‘i’ or ‘a’") 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 62: Line 62:
data.nocat = parent_args["nocat"] and true or false
data.nocat = parent_args["nocat"] and true or false
data.g = genders[g]
data.g = genders[g]
data.nopl = parent_args["nopl"] and true or false
if data.proper then data.nopl = true end
data.decl_type = decl_type
data.decl_type = decl_type
data.pos = parent_args["pos"] or "nouns"
-- Generate the forms
-- Generate the forms
Line 73: 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 123: 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')
table.insert(ret, '| ' .. link(show_form(data.forms[case_short .. '_p'])) .. '\n')
if not data.nopl then
table.insert(ret, '| ' .. link(show_form(form_p)) .. '\n')
end
end
end
return table.concat(ret)
return table.concat(ret)
Line 141: Line 146:
!  
!  
! Singular
! Singular
]=] .. (data.nopl and "\n" or [=[
! Plural
! Plural
]=] .. make_cases(data) .. [=[
]=]) .. make_cases(data) .. [=[
|}</div></div>]=]
|}</div></div>]=]