Jump to content

Module:nb-verb-common-irreg

From Wiktionary, the free dictionary

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local lang = require("Module:languages").getByCode("nb")
 
function export.main(frame)
    args = frame:getParent().args
    PAGENAME = mw.title.getCurrentTitle().text
    if PAGENAME:find('e$') and mw.ustring.len(PAGENAME) > 2 then
        root = mw.ustring.sub(PAGENAME, 1,  mw.ustring.len(PAGENAME)-1)
    else
        root = PAGENAME
    end
    
    length = mw.ustring.len(root)
    
    local data = {lang = lang, pos_category = "verbs", categories = {lang:getCanonicalName() .. " irregular verbs"}, inflections = {}}
    
    local present_tense = {label = 'present tense'}
    local past_tense = {label = 'past tense'}
    local past_participle = {label = 'past participle'}
    local passive_infinitive = {label = 'passive infinitive'}
    local present_participle = {label = 'present participle'}
    local imperative = {label = 'imperative'}
    
    t5 = mw.ustring.sub(root, length-4, length)
    t4 = mw.ustring.sub(root, length-3, length)
    t3 = mw.ustring.sub(root, length-2, length)
    t2 = mw.ustring.sub(root, length-1, length)
    
    if t4 == 'legg' then
    	p1 = mw.ustring.sub(root, 1, length-4)

        table.insert(present_tense, p1 .. 'legger')
        table.insert(past_tense, p1 .. 'la')
        table.insert(past_participle, p1 .. 'lagt')
        table.insert(passive_infinitive, p1 .. 'legges')
        table.insert(present_participle, p1 .. 'leggende')
        table.insert(imperative, p1 .. 'legg')
            
    elseif t4 == 'sett' then
    	p1 = mw.ustring.sub(root, 1, length-4)

        table.insert(present_tense, p1 .. 'setter')
        table.insert(past_tense, p1 .. 'satte')
        table.insert(past_participle, p1 .. 'satt')
        table.insert(passive_infinitive, p1 .. 'settes')
        table.insert(present_participle, p1 .. 'settende')
        table.insert(imperative, p1 .. 'sett')
    
    elseif t3 == 'stå' then
        p1 = mw.ustring.sub(PAGENAME, 1, length-3)
      
        table.insert(present_tense, p1 .. 'står')
        table.insert(past_tense, p1 .. 'sto')
        table.insert(past_tense, p1 .. 'stod')
        table.insert(past_participle, p1 .. 'stått')
        table.insert(passive_infinitive, p1 .. 'stås')
        table.insert(present_participle, p1 .. 'stående')
        table.insert(imperative, p1 .. 'stå')
        
    elseif t2 == 'gå' then
        p1 = mw.ustring.sub(PAGENAME, 1, length-2)
      
        table.insert(present_tense, p1 .. 'går')
        table.insert(past_tense, p1 .. 'gikk')
        table.insert(past_participle, p1 .. 'gått')
        table.insert(passive_infinitive, p1 .. 'gås')
        table.insert(present_participle, p1 .. 'gående')
        table.insert(imperative, p1 .. 'gå')
    else
    	return "<span style=\"color:Red\">'''The verb ''" .. PAGENAME .. "'' is not supported by this template.'''</span> Use {{[[Template:nb-verb-irreg|nb-verb-irreg]]|<present tense>|etc.}} instead" 
    end

    table.insert(data.inflections, present_tense)
    table.insert(data.inflections, past_tense)
    table.insert(data.inflections, past_participle)
  
    if not no_passive_inf then
        table.insert(data.inflections, passive_infinitive)
    end
 
    if not no_present_part then
        table.insert(data.inflections, present_participle)
    end
 
    if not no_imp then
        table.insert(data.inflections, imperative)
    end
    
    return require("Module:headword").full_headword(data)
end

return export