Module:sux-registers

From Wiktionary, the free dictionary
Jump to navigation Jump to search


local export = {}
local m_register_data = mw.loadData("Module:sux-registers/data")
local lang = require("Module:languages").getByCode("sux")
local m_links = require("Module:links")
local m_strutils = require("Module:string utilities")

local function format_list_items(items)
    local result = {}

    for _, item in ipairs(items) do
        item = m_links.full_link { lang = lang, term = item.term, tr = item.tr }
        table.insert(result, '\n' .. item)
    end

    return table.concat(result)
end

function export.create_list(args)
    if type(args) ~= "table" then
        error("expected table, got " .. type(args))
    end

    local output = {}

    table.insert(output, [[<div class="term-list ul-column-count" data-column-count="1" >]])

    table.insert(output, format_list_items(args))

    table.insert(output, '</div>')

    return table.concat(output)
end

function export.show(frame)
    local args = frame:getParent().args

    if args[1] or args[1] ~= "" then
        meaning = args[1]
    else
        error("Specify a meaning.")
    end

    local data = m_register_data[meaning] or nil

    if data then
        local emegir = data.emegir
        local emesal = data.emesal

        local template = [===[
        {| class="floatright wikitable" style="max-width: 25em;"
        |+ style="text-align:center; white-space: nowrap;"| “{meaning}”
        |- style="text-align:center;"
        ! [[w:Sumerian language#Dialects|Emegir]]
        | {emegir}
        |- style="text-align:center;"
        ! [[w:Sumerian language#Dialects|Emesal]]
        | {emesal}
        |-
        |{\cl}]===]

        local forms = {}

        forms["meaning"] = meaning
        forms["emegir"] = export.create_list(emegir)
        forms["emesal"] = export.create_list(emesal)

        return m_strutils.format(template, forms)
    else
        error("The sense “" .. meaning .. "” is not found in [[Module:sux-registers/data]].")
    end
end

return export