Difference between revisions of "Module:Template translation"

Jump to navigation Jump to search
m
hope this fixes this dummy bug of namespaces
>Verdy p
m (preserve the namespace as it is resolved when testing other languages (may be needed for te main namespace) - workaround)
>Verdy p
m (hope this fixes this dummy bug of namespaces)
Line 78: Line 78:
             title = mw.title.new(pagename, namespace) -- Costly
             title = mw.title.new(pagename, namespace) -- Costly
         end
         end
    end
   
    -- At this point the title should exist, otherwise render a red link to the missing page
    if (title.id == 0)
    then
    return '[[' .. title.prefixedText .. ']]'
     end
     end
      
      
Line 91: Line 85:
     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(title.prefixedText .. '/' .. 'en', namespace) -- Costly
         local newtitle = mw.title.new(pagename .. '/' .. 'en', namespace) -- Costly
         -- Use the translation when it exists
         -- Use the translation when it exists
         if (newtitle.id ~= 0)
         if (newtitle.id ~= 0)
Line 99: Line 93:
     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(title.prefixedText .. '/' .. subpage, namespace) -- Costly
         local newtitle = mw.title.new(pagename .. '/' .. subpage, namespace) -- Costly
         if (newtitle.id == 0)
         if (newtitle.id == 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(title.prefixedText .. '/' .. 'en', namespace) -- Costly
             newtitle = mw.title.new(pagename .. '/' .. 'en', namespace) -- Costly
         end
         end
         -- Use the translation when it exists
         -- Use the translation when it exists
Line 110: Line 104:
             title = newtitle
             title = newtitle
         end
         end
    end
   
    -- 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)
    then
    return '[[' .. title.prefixedText .. ']]'
     end
     end
      
      
Line 128: Line 128:
         end
         end
     end
     end
   
     return frame:expandTemplate{title = title, args = arguments}
     return frame:expandTemplate{title = title, args = arguments}
end
end


return this
return this
Anonymous user

Navigation menu