Module:Sandbox/Jackmcbarn: Difference between revisions

Content deleted Content added
Jackmcbarn (talk | contribs)
add quick test thing
Jackmcbarn (talk | contribs)
m Reverted edits by Jackmcbarn (talk) to last version by Le Deluge
Tags: Replaced Rollback
 
(12 intermediate revisions by 2 users not shown)
Line 1:
local getTarget = require('Module:Redirect').getTarget
local translationwrapper = {}
local p = {}
 
local function translationwrapper.createpagetype(argsnsText)
return nsText == '' and 'articles' or (mw.ustring.lower(nsText) .. ' pages')
if not args.temapping then
end
args.temapping = {}
for k,v in pairs(args.etmapping) do
if type(v) == 'table' then
for _,v2 in ipairs(v) do
args.temapping[v2] = k
end
else
args.temapping[v] = k
end
end
end
 
function p.main(frame)
local mt = {}
local currentTitle = mw.title.getCurrentTitle()
function mt.__index(t, k)
local etmappingtarget = args.etmapping[k]getTarget(currentTitle)
if type[etmapping] == 'table'target then
local currentNsText, targetNsText = currentTitle.nsText, mw.title.new(target).nsText
for _,v in ipairs(etmapping) do
if currentNsText ~= targetNsText then
local retval = src[v]
return string.format('[[:Category:Cross-namespace redirects from %s]][[:Category:Cross-namespace redirects to %s]]', pagetype(currentNsText), pagetype(targetNsText))
if retval ~= nil then
return retval
end
end
if args.strict then
return nil
else
return src[k]
end
elseif etmapping ~= nil then
local retval = src[etmapping]
if retval ~= nil then
return retval
elseif args.strict then
return nil
else
return src[k]
end
elseif args.strict then
error('Tried to read untranslated key in strict mode: ' .. k)
else
return src[k]
end
end
return '[[:Category:Pages incorrectly tagged as cross-namespace redirects]]'
function mt.__newindex(t, k, v)
local etmapping = args.etmapping[k]
if type[etmapping] == 'table' then
etmapping = etmapping[1]
elseif etmapping == nil then
if args.strict then
error('Tried to write untranslated key in strict mode: ' .. k)
else
etmapping = k
end
end
src[etmapping] = v
end
function mt.__pairs(t)
end
function mt.__ipairs(t)
return ipairs(args.src)
end
return setmetatable({}, mt)
end
 
local p = {}
 
function p.main(frame)
mw.logObject(frame.args, 'frame.args')
mw.logObject(frame:getParent().args, 'frame:getParent().args')
end
 
function p.x(frame)
mw.title.new(tonumber(frame.args[1]))
end