local p = {}
function p.link(word, form)
if word == form then
link = word
else
link = "[[" .. form .. "#Norwegian Nynorsk|" .. form .. "]]"
end
link = "'''" .. link .. "'''"
return link
end
function p.main(frame)
args = frame:getParent().args
PAGENAME = mw.title.getCurrentTitle().text
NAMESPACE = mw.title.getCurrentTitle().nsText
length = PAGENAME:len()
cons1 = PAGENAME:sub(1, 1):find('[bcdfghjklmnpqrstvxz]')
cons2 = PAGENAME:sub(2, 2):find('[bcdfghjklmnpqrstvxz]')
if length == 3 and cons1 and cons2 then
root = PAGENAME
elseif PAGENAME:find('[ae]$') and length > 2 then
root = PAGENAME:sub(1, length-1)
else
root = PAGENAME
end
if root:sub(length-1, length-1) == 'j' and length > 3 then
root2 = root:sub(1, length-2)
else
root2 = root
end
if args['second_root'] then
second_root = args['second_root']
else
second_root = root
end
if args['no_present_part'] then
no_present_part = 1
else
no_present_part = nil
end
if args['no_passive_inf'] then
no_passive_inf = 1
else
no_passive_inf = nil
end
if args['no_imp'] then
no_imp = 1
else
no_imp = nil
end
if PAGENAME:find('ast$') or PAGENAME:find('as$') then
no_present_part = 1
no_passive_inf = 1
end
present_tense = p.link(PAGENAME, args[1] or (NAMESPACE == "Template" and "word") or error("Unhelpful error"))
past_tense = p.link(PAGENAME, args[2] or (NAMESPACE == "Template" and "word") or error("Unhelpful error"))
past_participle = p.link(PAGENAME, args[3] or (NAMESPACE == "Template" and "word") or error("Unhelpful error"))
if args[4] and args[4]:find('st$') then
passive_infinitive = p.link(PAGENAME, args[4])
else
passive_infinitive = p.link(PAGENAME, second_root .. 'ast')
end
if args[5] then
present_participle = p.link(PAGENAME, args[5])
else
present_participle = p.link(PAGENAME, second_root .. 'ande')
end
if args[6] or args['imp'] then
imperative = p.link(PAGENAME, args[6] or args['imp'])
else
if root:sub(length-2, length-1) == 'mm' then
imperative = p.link(PAGENAME, root:sub(1, length-2))
else
imperative = p.link(PAGENAME, root2)
end
end
-- extra arguments
if args['pres_tense2'] then
present_tense = present_tense .. '/' .. p.link(PAGENAME, args['pres_tense2'])
end
if args['past_tense2'] then
past_tense = past_tense .. '/' .. p.link(PAGENAME, args['past_tense2'])
end
if args['past_part2'] then
past_participle = past_participle .. '/' .. p.link(PAGENAME, args['past_part2'])
end
if args['imp2'] then
imperative = imperative .. '/' .. p.link(PAGENAME, args['imp2'])
end
--
if no_passive_inf or args['first_four'] then
passive = ''
else
passive = "; ''passive infinitive'' " .. passive_infinitive
end
if no_present_part or args['first_four'] then
present_part = ''
else
present_part = "; ''present participle'' " .. present_participle
end
if no_imp or args['first_four'] then
imp = ''
else
imp = "; ''imperative'' " .. imperative
end
text = string.format("'''%s''' (''present tense'' %s; ''past tense'' %s; ''past participle'' %s%s%s%s)",
PAGENAME, present_tense, past_tense, past_participle, passive, present_part, imp)
return text
end
return p