Module:CountryData: Difference between revisions
// via Wikitext Extension for VSCode Tag: Reverted |
// via Wikitext Extension for VSCode Tag: Reverted |
||
| Line 168: | Line 168: | ||
local loader = require('Module:DatasetLoader') | local loader = require('Module:DatasetLoader') | ||
local data = loader.get('CountryDataset') | local data = loader.get('CountryDataset') | ||
-- Fallback to server-side JSON loader if loader fails | |||
if not data or type(data) ~= 'table' or not data.countries or next(data.countries) == nil then | |||
if mw.loadJsonData then | |||
local ok, jsonData = pcall(mw.loadJsonData, 'Data:CountryDataset.json') | |||
if ok and type(jsonData) == 'table' then | |||
data = jsonData | |||
end | |||
end | |||
end | |||
-- Fallback to DEFAULT_DATA if still empty | |||
if not data or type(data) ~= 'table' or not data.countries then | |||
data = DEFAULT_DATA | |||
end | |||
-- Ensure minimum data structure | -- Ensure minimum data structure | ||