Dokumentaciju za ovaj modul možete napraviti na stranici Modul:headword/dok

local gen = require("Module:gender and number")
local languages = mw.loadData("Module:languages")

local export = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
    local args = frame:getParent().args
    PAGENAME = mw.title.getCurrentTitle().text
    NAMESPACE = mw.title.getCurrentTitle().nsText
    local ret = ""
    
    -- Language code
    local lang = args[1] or error("Jezični kod nije specificiran. Molimo idite na parametar 1 za invociranje modula.")
    local langinfo = languages[lang] or error("Jezični kod \"" .. lang .. "\" nije ispravan.")
    
    -- Headword
    local sc = args["sc"] or ""; if sc == "" then sc = langinfo.scripts[1] end
    local head = args["head"] or ""; if head == "" then head = PAGENAME end
    
    ret = ret .. frame:expandTemplate{ title = sc, args = { head, lang = lang, face = "head" } }
    
    -- Transliteration
    local tr = args["tr"] or ""
    
    if tr ~= "" then
        ret = ret .. " (" .. tr .. ")"
    end
    
    -- Categories
    if NAMESPACE == "" then
        local categories = {}
        
        local pos = args[2]; if pos == "" then pos = nil end
        if pos then
            -- Make the plural form of the part of speech
            if pos:find("x$") then
                pos = pos .. "es"
            elseif pos ~= "punctuation" or pos ~= "phrasebook" then
                pos = pos .. "s"
            end
            
            table.insert(categories, langinfo.names[1] .. " " .. pos)
        end
        
        local cat2 = args["cat2"]; if cat2 == "" then cat2 = nil end
        if cat2 then
            table.insert(categories, langinfo.names[1] .. " " .. cat2)
        end
        
        local cat3 = args["cat3"]; if cat3 == "" then cat3 = nil end
        if cat3 then
            table.insert(categories, langinfo.names[1] .. " " .. cat3)
        end
        
        -- Add the categories with the appropriate sort key
        local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
        for key, cat in ipairs(categories) do
            ret = ret .. "[[Category:" .. cat .. (sort_key and "|" .. sort_key or "") .. "]]"
        end
    end
    
    return ret
end

return export