Module:NarratorListModule: Difference between revisions
From The Seven Sages of Rome
No edit summary |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
local p = {} | 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 | 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] and result[1].values then | |||
-- Check if the "Is Variety Of" value exists | |||
local parentLanguage = result[1].values["Is Variety Of"] | |||
local | |||
-- | -- If there's a parent language, recursively find its root | ||
if parentLanguage then | |||
return p.findRootLanguage(parentLanguage) | |||
-- | else | ||
-- Return the current language if no parent is found | |||
return language | |||
end | end | ||
else | |||
-- If no valid result, return the original language | |||
return language | |||
end | end | ||
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] and result[1].values then
-- Check if the "Is Variety Of" value exists
local parentLanguage = result[1].values["Is Variety Of"]
-- If there's a parent language, recursively find its root
if parentLanguage then
return p.findRootLanguage(parentLanguage)
else
-- Return the current language if no parent is found
return language
end
else
-- If no valid result, return the original language
return language
end
end
return p