Module:GameText/loaddata

local cache = mw.ext.LuaCache

local flip flip = function(data) if type(data) ~= 'table' then return data end local result = {} for k, v in pairs(data) do		if type(v) == 'table' then result[k] = flip(v) else if result[v] then -- conflict local i = 2 while result[v .. i] do 					i = i + 1 end result[v .. i] = k			else result[v] = k			end end end return result end

return { load = function(lang) local data = cache.get(':_gametext:data:'..lang) if data then return data else -- fallback local info = require('Module:GameText/db-'..lang) or {} -- return table of mw.loadData has a metatable, can not be used for cache.set and mw.loadData. -- flip local flipped = flip(info) -- cache it. -- This cache can be purged by: -- * purge `Module:GameText/db- ` or `Module:GameText/db- /doc` page -- * lua code: `require('Module:GameText/loaddata').purge` -- * template code: `` cache.set( ':_gametext:data:'..lang, {info=info, flipped=flipped}) -- cache for last revision local last_rev = mw.getCurrentFrame:callParserFunction{ name = 'REVISIONID', args = { 'Module:GameText/db-' .. lang } } cache.set(':_gametext:data:last_rev:'..lang, last_rev) end end, purge = function(lang) cache.delete(':_gametext:data:'..lang) cache.delete(':_gametext:data:last_rev:'..lang) end, }