Actions

Module

Module:gloss list

From SUALEX

Documentation for this module may be created at Module:gloss list/doc

-- Module:gloss_list

local p = {}

function p.invoke(frame)
    local lexicon   = require("Module:lexicon")
    local utilities = require("Module:utilities")
    local format    = require("Module:format")

    local args = frame.args or {}
    local gloss_item = args[1] or ""
    local gloss_pref = args.gloss or "en"  -- en | es | all | no

    if gloss_item == "" then
        return "<strong class='error'>Please provide a gloss, e.g. {{gloss list|water}}</strong>"
    end

    lexicon.preload_all_lexicons()

    local entries = lexicon.get_entries_by_gloss(gloss_item)

    local rows = {}
    table.insert(rows, '{| class="wikitable searchable sortable"\n! Term !! Language')

    for _, res in ipairs(entries) do
        local entry = res.entry
        local lang_code = res.lang

        for _, t in ipairs(entry.term or {}) do
            local term_html = format.render_term(
                lang_code,
                t.term_item,
                t.homonym,
                t.display_form,
                false,
                nil,
                gloss_pref
            )

            table.insert(
                rows,
                "|-\n| " .. term_html .. " || " .. format.language_name(lang_code)
            )
        end
    end

    table.insert(rows, "|}")
    return utilities.join_strings(rows, "\n")
end

return p