Module:Template translation: Difference between revisions

m
mw.title.new() no longer returns a tile object with id=0, but nil, if page is not found. Fix it.
m (there are other chars that generate exceptions in mw.language.isKnownLanguageTag, and some language codes still not validated correctly; check this correctly)
m (mw.title.new() no longer returns a tile object with id=0, but nil, if page is not found. Fix it.)
Line 103:
if (namespace ~= '') -- Checks for namespace parameter for custom ns.
then
title = mw.title.new(pagename, namespace) or {} -- Costly
else -- Supposes that set page is in ns10.
namespace = 'Template'
title = mw.title.new(pagename, namespace) or {} -- Costly
if (title.id or 0) == 0)
then -- not found in the Template namespace, assume the main namespace (for backward compatibility)
namespace = ''
title = mw.title.new(pagename, namespace) or {} -- Costly
end
end
Line 123:
then
-- Check if a translation of the pagename exists in English
local newtitle = mw.title.new(pagename .. '/' .. 'en', namespace) or {} -- Costly
-- Use the translation when it exists
if (newtitle.id or 0) ~= 0)
then
title = newtitle
Line 131:
else
-- Check if a translation of the pagename exists in that language
local newtitle = mw.title.new(pagename .. '/' .. subpage, namespace) or {} -- Costly
if (newtitle.id or 0) == 0)
then
-- Check if a translation of the pagename exists in English
newtitle = mw.title.new(pagename .. '/' .. 'en', namespace) or {} -- Costly
end
-- Use the translation when it exists
if (newtitle.id or 0) ~= 0)
then
title = newtitle
Line 145:
-- At this point the title should exist, otherwise render a red link to the missing page (resolved in its assumed namespace)
if (title.id or 0) == 0)
then
return '[[' .. title.prefixedText .. ']]'
Anonymous user