Module:NarratorListModule

From The Seven Sages of Rome
Revision as of 13:21, 25 March 2025 by Noeth (talk | contribs)

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

local p = {}

function p._findRoot(language)
    local current = language
    while true do
        -- Query for the 'Is Variety Of' property of the current language
        local results = mw.smw.ask({
            '[[Category:Language]]',
            '[[' .. current .. ']]',
            '?Is Variety Of'
        })
        
        -- Exit if no results or invalid response
        if not results or #results == 0 then break end
        
        -- Extract parent data from the first result
        local parentData = results[1]['Is Variety Of']
        
        -- Exit if no parent found
        if not parentData or #parentData == 0 then break end
        
        -- Move to the parent language (using fulltext for page name)
        current = parentData[1].fulltext
    end
    return current
end

function p.main(frame)
    local language = frame.args[1]  -- Get input language from template
    return p._findRoot(language)
end

return p