Difference between revisions of "Module:Template translation"

Jump to navigation Jump to search
Add pagename parameter, refactor. @Shirayuki: This should work from wikitext.
>Shirayuki
m (Undid revision 3381029 by Shirayuki (talk))
>Tacsipacsi
(Add pagename parameter, refactor. @Shirayuki: This should work from wikitext.)
Line 45: Line 45:
end
end


--[[Get the last subpage of the current page if it is a translation.
--[[Get the last subpage of an arbitrary page if it is a translation.
    To be used from templates.
    ]]
function this.getLanguageSubpage(frame)
local title = frame and frame.args[1]
if not title or title == '' then
title = mw.title.getCurrentTitle()
end
return this._getLanguageSubpage(title)
end
 
--[[Get the last subpage of an arbitrary page if it is a translation.
    To be used from Lua.
     ]]
     ]]
function this.getLanguageSubpage()
function this._getLanguageSubpage(title)
if type(title) == 'string' then
title = mw.title.new(title)
end
if not title then
-- invalid title
return nil
end
--[[This code does not work in all namespaces where the Translate tool works.
--[[This code does not work in all namespaces where the Translate tool works.
--  It works in the main namespace on Meta because it allows subpages there
--  It works in the main namespace on Meta because it allows subpages there
Line 60: Line 79:
--  bug of Meta-Wiki. The work-around is to split the full title and then
--  bug of Meta-Wiki. The work-around is to split the full title and then
--  get the last titlepart.
--  get the last titlepart.
local subpage = mw.title.getCurrentTitle().subpageText
local subpage = title.subpageText
--]]
--]]
    local titleparts = mw.text.split(mw.title.getCurrentTitle().fullText, '/')
local titleparts = mw.text.split(title.fullText, '/')
    local subpage = titleparts[#titleparts]
local subpage = titleparts[#titleparts]
    return this.checkLanguage(subpage, '')
return this.checkLanguage(subpage, '')
end
 
--[[Get the last subpage of the current page if it is a translation.
    ]]
function this.getCurrentLanguageSubpage()
return this._getLanguageSubpage(mw.title.getCurrentTitle())
end
end


Line 70: Line 95:
     ]]
     ]]
function this.getMainLanguageSubpage()
function this.getMainLanguageSubpage()
parts = mw.text.split( this.getLanguageSubpage(), '-' )
parts = mw.text.split( this.getCurrentLanguageSubpage(), '-' )
return parts[1]
return parts[1]
end
end
Line 78: Line 103:
     ]]
     ]]
function this.getFrameLanguageSubpage(frame)
function this.getFrameLanguageSubpage(frame)
    local titleparts = mw.text.split(frame:getParent():getTitle(), '/')
return this._getLanguageSubpage(frame:getParent():getTitle())
    local subpage = titleparts[#titleparts]
    return this.checkLanguage(subpage, '')
end
end


Line 161: Line 184:
     if (subpage == '')
     if (subpage == '')
     then
     then
         subpage = this.getLanguageSubpage()
         subpage = this.getCurrentLanguageSubpage()
     end
     end
     if (subpage == '')
     if (subpage == '')
Anonymous user

Navigation menu