Difference between revisions of "Module:Template translation"

Jump to navigation Jump to search
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)
en>Verdy p
m (arguments still need to be copied (they are not a proper table))
en>Verdy p
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: Line 109:
end
end


--[[If on a translation subpage (like Foobar/de), this function renders
--[[If on a translation subpage (like Foobar/de), this function returns
     a given template in the same language, if the translation is available.
     a given template in the same language, if the translation is available.
     Otherwise, the template is rendered in its default language, without
     Otherwise, the template is returned in its default language, without
     modification.
     modification.
     This is aimed at replacing the current implementation of Template:TNT.
     This is aimed at replacing the current implementation of Template:TNTN.
 
    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.renderTranslatedTemplate(frame)
function this.getTranslatedTemplate(frame)
     local args = frame.args
     local args = frame.args
     local pagename = args['template']
     local pagename = args['template']
Line 167: Line 171:
         end
         end
     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.
      
      
     -- At this point the title should exist, otherwise render a red link to the missing page (resolved in its assumed namespace)
    Note that translatable templates cannot transclude themselves other
     if title.id == nil
    translatable templates, as it will recurse on TNT. Use TNTN instead
     then
    to return only the effective template name to expand externally, with
    return '[[' .. title.prefixedText .. ']]'
    template parameters also provided externally.
    end
    ]]
   
function this.renderTranslatedTemplate(frame)
local title, found = this.getTranslatedTemplate(frame)
     -- At this point the title should exist prior to performing the expansion
    -- of the template, otherwise render a red link to the missing page
    -- (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 .. ']]'
end
 
     -- Copy args pseudo-table to a proper table so we can feed it to expandTemplate.
     -- Copy args pseudo-table to a proper table so we can feed it to expandTemplate.
     -- Then render the pagename.
     -- Then render the pagename.
Line 199: Line 222:
         end
         end
     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['template'] = title -- 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['namespace'] = nil -- discard the specified namespace override
     arguments['uselang'] = args['uselang'] -- argument forwarded into parent frame
     arguments['uselang'] = args['uselang'] -- argument forwarded into parent frame
     arguments['noshift'] = args['noshift'] -- argument forwarded into parent frame
     arguments['noshift'] = args['noshift'] -- argument forwarded into parent frame
      
      
     return frame:expandTemplate{title = ':' .. title.prefixedText, args = arguments}
     return frame:expandTemplate{title = ':' .. title, args = arguments}
end
end


return this
return this
Anonymous user

Navigation menu