Difference between revisions of "Module:Template translation"

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

Navigation menu