Module:NarratorListModule: Difference between revisions
From The Seven Sages of Rome
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 12: | Line 12: | ||
-- Check if we received a valid result | -- Check if we received a valid result | ||
if result and result[1] | if result and result[1] then | ||
-- Check if | local values = result[1].values | ||
local parentLanguage = | -- 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) | return p.findRootLanguage(parentLanguage) | ||
end | end | ||
end | end | ||
-- If no parent is found, return the current language (this is the root language) | |||
return language | |||
end | end | ||
return p | return p | ||
Revision as of 13:10, 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 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