Module:NarratorListModule: Difference between revisions
From The Seven Sages of Rome
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 3: | Line 3: | ||
-- Function to recursively find the root language | -- Function to recursively find the root language | ||
function p.findRootLanguage(language) | function p.findRootLanguage(language) | ||
-- Query | -- Query parameters | ||
local query = string.format('[[%s]] | local query = { | ||
conditions = string.format('[[%s]]', language), | |||
printouts = { 'Is Variety Of' } | |||
} | |||
-- Debugging: | -- Execute the query | ||
local result = mw.smw.getQueryResult(query) | |||
-- Debugging: Log the result structure | |||
mw.log("Query result: " .. mw.text.jsonEncode(result)) | mw.log("Query result: " .. mw.text.jsonEncode(result)) | ||
-- Check if we received a valid result | -- Check if we received a valid result | ||
if result and result | if result and result.results then | ||
for _, pageData in pairs(result.results) do | |||
local parentLanguage = pageData.printouts["Is Variety Of"] | |||
if parentLanguage and #parentLanguage > 0 then | |||
local parentLanguage = | return p.findRootLanguage(parentLanguage[1].fulltext) -- Recursively find the root language | ||
end | |||
end | end | ||
end | end | ||
Revision as of 13:14, 25 March 2025
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 parameters
local query = {
conditions = string.format('[[%s]]', language),
printouts = { 'Is Variety Of' }
}
-- Execute the query
local result = mw.smw.getQueryResult(query)
-- Debugging: Log the result structure
mw.log("Query result: " .. mw.text.jsonEncode(result))
-- Check if we received a valid result
if result and result.results then
for _, pageData in pairs(result.results) do
local parentLanguage = pageData.printouts["Is Variety Of"]
if parentLanguage and #parentLanguage > 0 then
return p.findRootLanguage(parentLanguage[1].fulltext) -- Recursively find the root language
end
end
end
-- If no parent is found, return the current language (this is the root language)
return language
end
return p