Más acciones
performance optimization: load translation units’ contents just in time using a metatable; don’t load them if they wouldn’t be used on the page |
m 1 revisión importada |
(Sin diferencias)
|
Revisión actual - 02:18 24 may 2021
La documentación para este módulo puede ser creada en Módulo:ModuleMsg/doc
local p = {}
function p.get_msgs(frame, pagename, lang)
local ret = {}
local msgs = {}
local page = mw.title.new(pagename)
local raw = page:getContent()
for msgname in string.gmatch(raw, '<!%-%-T:(.-)%-%->') do
msgs[msgname] = true
end
local retmeta = {
__index = function(t, msgname)
if msgs[msgname] then
local msgvalue = mw.title.new('Translations:' .. pagename .. '/' .. msgname .. '/' .. lang):getContent()
if msgvalue == nil then
-- English fallback
msgvalue = mw.title.new('Translations:' .. pagename .. '/' .. msgname .. '/en'):getContent()
end
rawset(t, msgname, msgvalue)
return msgvalue
else
return nil
end
end
}
return setmetatable(ret, retmeta)
end
return p