Module:Template translation: Difference between revisions
Jump to navigation
Jump to search
add exceptions for Help:Subpages/subpage and friends
(Created page with "local this = {} function this.checkLanguage(subpage, default) --[[Check first if there's an any invalid character that would cause the mw.language.isKnownLanguage...") |
Mediawiki>Shirayuki (add exceptions for Help:Subpages/subpage and friends) |
||
Line 36: | Line 36: | ||
and subpage ~= "sandbox" | and subpage ~= "sandbox" | ||
and subpage ~= "testcases" | and subpage ~= "testcases" | ||
and subpage ~= "init" | |||
and subpage ~= "preload" | |||
and subpage ~= "subpage" | |||
and subpage ~= "subpage2" | |||
and subpage ~= "sub-subpage" | |||
and subpage ~= "sub-sub-subpage" | |||
and subpage ~= "sub-sub-sub-subpage" | |||
then | then | ||
return subpage | return subpage | ||
Line 43: | Line 50: | ||
end | end | ||
--[[Get the last subpage of the | --[[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. | function this._getLanguageSubpage(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. | --[[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 58: | Line 84: | ||
-- 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 = | local subpage = title.subpageText | ||
--]] | --]] | ||
local titleparts = mw.text.split(title.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 | end | ||
Line 68: | Line 100: | ||
]] | ]] | ||
function this.getMainLanguageSubpage() | function this.getMainLanguageSubpage() | ||
parts = mw.text.split( this. | parts = mw.text.split( this.getCurrentLanguageSubpage(), '-' ) | ||
return parts[1] | return parts[1] | ||
end | end | ||
Line 76: | Line 108: | ||
]] | ]] | ||
function this.getFrameLanguageSubpage(frame) | function this.getFrameLanguageSubpage(frame) | ||
return this._getLanguageSubpage(frame:getParent():getTitle()) | |||
end | end | ||
Line 159: | Line 189: | ||
if (subpage == '') | if (subpage == '') | ||
then | then | ||
subpage = this. | subpage = this.getCurrentLanguageSubpage() | ||
end | end | ||
if (subpage == '') | if (subpage == '') |