Module:Template translation: Difference between revisions

m
Undo revision 7059330 by Techman224 (talk) sorry but I need to see the error, because the revert breaks other pages
(revert, causing script errors all over the place)
m (Undo revision 7059330 by Techman224 (talk) sorry but I need to see the error, because the revert breaks other pages)
Line 58:
]]
function this.renderTranslatedTemplate(frame)
local templateargs = frame.args['template']
local pagename = args['template']
 
--[[Check whether the templatepagename is actually in the Template namespace, or
if we're transcluding a main-namespace page.
(added for backward compatibility of Template:TNT)
]]
local namespace = 'Template'title
iflocal namespace = (frame.args['namespace']~= or '')--checks for namespace parameter for custom ns
if (namespace ~= '') -- Checks for namespace parameter for custom ns.
then
namespace title = framemw.args['title.new(pagename, namespace']) -- Costly
else --supposes Supposes that set page is in ns10.
local templateFullTitletitle = mw.title.new(templatepagename, namespace'Template') -- Costly
if (templateFullTitletitle.id == 0)
then -- not found in the Template namespace, assume the main namespace (for backward compatibility)
namespacetitle = mw.title.new(pagename, '') -- Costly
end
end
-- GetAt thethis lastpoint subpagethe andtitle checkshould ifexist, itotherwise matchesrender a knownred link to the languagemissing codepage
if (title.id == 0)
local langcode = 'en' -- default language template subpage to render
then
return '[[' .. title.prefixedText .. ']]'
end
-- Get the last subpage and check if it matches a known language code.
local subpage = this.getLanguageSubpage()
if (subpage ~== '')
then
-- Check if a translation of the templatepagename exists in that language; if so, put it in langcodeEnglish
local translationnewtitle = mw.title.new(templatetitle.prefixedText .. '/' .. subpage, namespace'en') -- Costly
if-- Use the (translation.id ~=when it 0)exists
if (newtitle.id ~= 0)
then
title = newtitle
end
else
-- Check if a translation of the pagename exists in that language
local newtitle = mw.title.new(title.prefixedText .. '/' .. subpage) -- Costly
if (newtitle.id == 0)
then
-- Check if a translation of the pagename exists in English
newtitle = mw.title.new(title.prefixedText .. '/' .. 'en') -- Costly
end
-- Use the translation when it exists
if (newtitle.id ~= 0)
then
langcodetitle = subpagenewtitle
end
end
 
-- Copy args pseudo-table to a proper table so we can feed it to expandTemplate.
-- Then render the templatepagename.
local arguments = {}
for k, v in pairs((frame:getParent() or {}).args) do
Line 105 ⟶ 126:
end
end
return frame:expandTemplate{title = namespace .. ':' .. template .. '/' .. langcodetitle, args = arguments}
end
 
Anonymous user