Module:Template translation: Difference between revisions

m
16 revisions imported
(Add fallback to _getLanguageSubpage for content language. Used by Template:Pagelang)
m (16 revisions imported)
 
(One intermediate revision by one other user not shown)
Line 36:
and subpage ~= "sandbox"
and subpage ~= "testcases"
and subpage ~= "init"
and subpage ~= "preload"
then
return subpage
Line 45 ⟶ 43:
end
 
--[[Get the last subpage of anthe arbitrarycurrent 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._getLanguageSubpagegetLanguageSubpage(title)
if type(title) == 'string' then
title = mw.title.new(title)
end
if not title then
-- invalid title
return mw.language.getContentLanguage():getCode()
end
--[[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
Line 79 ⟶ 58:
-- bug of Meta-Wiki. The work-around is to split the full title and then
-- get the last titlepart.
local subpage = mw.title.getCurrentTitle().subpageText
--]]
local titleparts = mw.text.split(mw.title.getCurrentTitle().fullText, '/')
local subpage = titleparts[#titleparts]
return this.checkLanguage(subpage, mw.language.getContentLanguage():getCode()'')
end
 
--[[Get the last subpage of the current page if it is a translation.
]]
function this.getCurrentLanguageSubpage()
return this._getLanguageSubpage(mw.title.getCurrentTitle())
end
 
Line 95 ⟶ 68:
]]
function this.getMainLanguageSubpage()
parts = mw.text.split( this.getCurrentLanguageSubpagegetLanguageSubpage(), '-' )
return parts[1]
end
Line 103 ⟶ 76:
]]
function this.getFrameLanguageSubpage(frame)
return this local titleparts = mw.text._getLanguageSubpagesplit(frame:getParent():getTitle(), '/')
local subpage = titleparts[#titleparts]
return this.checkLanguage(subpage, '')
end
 
Line 184 ⟶ 159:
if (subpage == '')
then
subpage = this.getCurrentLanguageSubpagegetLanguageSubpage()
end
if (subpage == '')