Difference between revisions 18626532 and 18626533 on frwiktionary

local languages = mw.loadData("Module:languages")
local export = {}

-- transliterate the text, if possible
function export.translit(lang, text)
    -- TODO: the table's information should be moved to [[Module:languages]]
    local translit_modules = {
        ["ae"] = "Module:Avst-translit",
(contracted; show full)        return ""
    end
end

-- Used by {{categorize}}
function export.template_categorize(frame)
    NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText

    local format = frame.args["format"]
    local args = frame:getParent().args
    
    local lang = args[1]
    local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
    local categories = {}
    local format = args["format"]
    
    if lang == "" or lang == nil then
        if NAMESPACE == "Template" then
            lang = "und"
        else
            error("Language code has not been specified. Please pass parameter 1 to the template.")
        end
    end
    
    local langinfo = languages[lang] or error("The language code \"" .. lang .. "\" is not valid.")
    
    local prefix = ""
    if format == "pos" then
        prefix = langinfo.names[1] .. " "
    elseif format == "topic" then
        prefix = lang .. ":"
    end
    
    local i = 2
    local cat = args[i]
    
    while cat do
        if cat ~= "" then
            table.insert(categories, prefix .. cat)
        end
        
        i = i + 1
        cat = args[i]
    end
    
    return export.format_categories(categories, lang, sort_key)
end

return export