Module:NarratorListModule

From The Seven Sages of Rome
Revision as of 13:10, 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)
    -- Query to get the "Is Variety Of" value for the given language
    local query = string.format('[[%s]]|?Is Variety Of', language)
    -- Execute the query using mw.smw.ask
    local result = mw.smw.ask(query)
    
    -- Debugging: Output the structure of the result to help diagnose the problem
    mw.log("Query result: " .. mw.text.jsonEncode(result))

    -- Check if we received a valid result
    if result and result[1] then
        local values = result[1].values
        -- Check if "Is Variety Of" exists in the values
        if values and values["Is Variety Of"] then
            local parentLanguage = values["Is Variety Of"]
            -- If there's a parent language, recursively find its root
            return p.findRootLanguage(parentLanguage)
        end
    end
    
    -- If no parent is found, return the current language (this is the root language)
    return language
end

return p