Module:Template translation: Difference between revisions

m
supplement for TNTN (to be used to solve self-recursions of TNT, with translatable templates trying to transclude other translatable templates also with TNT)
m (arguments still need to be copied (they are not a proper table))
m (supplement for TNTN (to be used to solve self-recursions of TNT, with translatable templates trying to transclude other translatable templates also with TNT))
Line 109:
end
 
--[[If on a translation subpage (like Foobar/de), this function rendersreturns
a given template in the same language, if the translation is available.
Otherwise, the template is renderedreturned in its default language, without
modification.
This is aimed at replacing the current implementation of Template:TNTTNTN.
 
This version does not expand the returned template name: this solves the
problem of self-recursion in TNT when translatable templates need themselves
to transclude other translable templates (such as Tnavbar).
]]
function this.renderTranslatedTemplategetTranslatedTemplate(frame)
local args = frame.args
local pagename = args['template']
Line 167 ⟶ 171:
end
end
-- At this point the title should exist
return title.prefixedText, title.id ~= nil
end
 
--[[If on a translation subpage (like Foobar/de), this function renders
a given template in the same language, if the translation is available.
Otherwise, the template is rendered in its default language, without
modification.
This is aimed at replacing the current implementation of Template:TNT.
Note that translatable templates cannot transclude themselves other
-- At this point the title should exist, otherwise render a red link to the missing page (resolved in its assumed namespace)
translatable templates, as it will recurse on TNT. Use TNTN instead
if title.id == nil
to return only the effective template name to expand externally, with
then
template parameters also provided externally.
return '[[' .. title.prefixedText .. ']]'
end]]
function this.renderTranslatedTemplate(frame)
local title, found = this.getTranslatedTemplate(frame)
-- At this point the title should exist prior to performing the expansion
-- At this pointof the title should existtemplate, otherwise render a red link to the missing page (resolved in its assumed namespace)
-- (resolved in its assumed namespace). If we don't tet this here, a
-- script error would be thrown. Returning a red link is consistant with
-- MediaWiki behavior when attempting to transclude inexistant templates.
if not found then
return '[[' .. title.prefixedText .. ']]'
end
 
-- Copy args pseudo-table to a proper table so we can feed it to expandTemplate.
-- Then render the pagename.
Line 199 ⟶ 222:
end
end
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 forwarded into parent frame
arguments['noshift'] = args['noshift'] -- argument forwarded into parent frame
return frame:expandTemplate{title = ':' .. title.prefixedText, args = arguments}
end
 
Anonymous user