Anonymous user
Module:Template translation: Difference between revisions
m
forward the noshift parameter to avoid infinite recursion
mNo edit summary |
m (forward the noshift parameter to avoid infinite recursion) |
||
Line 85:
end
function this.
local message, title
local pagename = basepagename
if (subpage or '') ~= ''
then
pagename = pagename .. '/' .. subpage
end
local valid, title = xpcall(function()
return mw.title.new(pagename, namespace) -- costly
end, function(msg) -- catch undocumented exception (!?)
-- thrown when namespace does not exist. The doc still
-- says it should return a title, even in that case...
message = msg
end)
if valid and title ~= nil and (title.id or 0) ~= 0
then
return title
end
return { -- "pseudo" mw.title object with id = nil in case of error
prefixedText = pagename, -- the only property we need below▼
▲ prefixedText = pagename,
}
end
Line 123 ⟶ 127:
if (namespace ~= '') -- Checks for namespace parameter for custom ns.
then
title = this.
else -- Supposes that set page is in ns10.
namespace = 'Template'
title = this.
if title.id ==
then -- not found in the Template namespace, assume the main namespace (for backward compatibility)
namespace = ''
title = this.
end
end
Line 143 ⟶ 147:
then
-- Check if a translation of the pagename exists in English
local newtitle = this.
-- Use the translation when it exists
if newtitle.id ~=
then
title = newtitle
Line 151 ⟶ 155:
else
-- Check if a translation of the pagename exists in that language
local newtitle = this.
if newtitle.id ==
then
-- Check if a translation of the pagename exists in English
newtitle = this.
end
-- Use the translation when it exists
if newtitle.id ~=
then
title = newtitle
Line 165 ⟶ 169:
-- At this point the title should exist, otherwise render a red link to the missing page (resolved in its assumed namespace)
if title.id ==
then
return '[[' .. title.prefixedText .. ']]'
Line 196 ⟶ 200:
arguments['template'] = title.prefixedText -- override the existing parameter of the base template name supplied with the full name of the actual template expanded
arguments['namespace'] = nil -- discard the specified namespace override
arguments['uselang'] = args
arguments['noshift'] = args
return frame:expandTemplate{title = ':' .. title.prefixedText, args = arguments}
|