Module:NarratorListModule

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

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

local p = {}

-- Function to recursively find the root language
function p.findRootLanguage(language)
    -- Construct the SMW query to find the parent language
    local query = string.format('[[%s]]|?Is Variety Of', language)
    -- Execute the query
    local result = mw.smw.ask{ query }

    -- Debugging: Log the query result
    mw.logObject(result, "Query result")

    -- Check if the result contains the 'Is Variety Of' property
    if result and result[language] and result[language]["Is Variety Of"] then
        local parentLanguage = result[language]["Is Variety Of"][1]
        -- Recursively find the root language
        return p.findRootLanguage(parentLanguage)
    end

    -- If no parent language is found, return the current language as the root
    return language
end

return p