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.titleNewtitle(pagenamenamespace, namespacebasepagename, subpage)
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
return {
prefixedText = pagename, -- the only property we need below
message = message,
idmessage = 0,message -- only for debugging
namespace = '',
prefixedText = pagename,
}
end
Line 123 ⟶ 127:
if (namespace ~= '') -- Checks for namespace parameter for custom ns.
then
title = this.titleNewtitle(pagenamenamespace, namespacepagename) -- Costly
else -- Supposes that set page is in ns10.
namespace = 'Template'
title = this.titleNewtitle(pagenamenamespace, namespacepagename) -- Costly
if title.id == 0nil
then -- not found in the Template namespace, assume the main namespace (for backward compatibility)
namespace = ''
title = this.titleNewtitle(pagenamenamespace, namespacepagename) -- Costly
end
end
Line 143 ⟶ 147:
then
-- Check if a translation of the pagename exists in English
local newtitle = this.titleNewtitle(namespace, pagename .. '/' .., 'en', namespace) -- Costly
-- Use the translation when it exists
if newtitle.id ~= 0nil
then
title = newtitle
Line 151 ⟶ 155:
else
-- Check if a translation of the pagename exists in that language
local newtitle = this.titleNewtitle(namespace, pagename .. '/' .., subpage, namespace) -- Costly
if newtitle.id == 0nil
then
-- Check if a translation of the pagename exists in English
newtitle = this.titleNewtitle(namespace, pagename .. '/' .., 'en', namespace) -- Costly
end
-- Use the translation when it exists
if newtitle.id ~= 0nil
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 == 0nil
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.['uselang'] -- argument addedforwarded tointo parent frame
arguments['noshift'] = args.['noshift'] -- argument addedforwarded tointo parent frame
return frame:expandTemplate{title = ':' .. title.prefixedText, args = arguments}
Anonymous user