Difference between revisions of "Module:Template translation"
Module:Template translation (view source)
Revision as of 16:11, 23 December 2013
, 16:11, 23 December 2013add some other "helper" functions and factorise one; I checked the code on a local wiki and here on Meta; the new functions can be used to autotranslate templates
>Verdy p m |
>Seb35 (add some other "helper" functions and factorise one; I checked the code on a local wiki and here on Meta; the new functions can be used to autotranslate templates) |
||
Line 2: | Line 2: | ||
function this.getLanguageSubpage() | function this.getLanguageSubpage() | ||
-- Get the last subpage | -- Get the last subpage of the current page if it is a translation | ||
local subpage = mw.title.getCurrentTitle().subpageText | local subpage = mw.title.getCurrentTitle().subpageText | ||
return this.checkLanguage(subpage,'') | |||
end | |||
function this.getFrameLanguageSubpage(frame) | |||
-- Get the last subpage of the current frame if it is a translation | |||
local titleparts = mw.text.split(frame:getParent():getTitle(),'/') | |||
local subpage = titleparts[#titleparts] | |||
return this.checkLanguage(subpage,'') | |||
end | |||
function this.getLanguage() | |||
-- Get the language of the current page | |||
local subpage = mw.title.getCurrentTitle().subpageText | |||
return this.checkLanguage(subpage,mw.language.getContentLanguage():getCode()) | |||
end | |||
function this.getFrameLanguage(frame) | |||
-- Get the language of the current frame | |||
local titleparts = mw.text.split(frame:getParent():getTitle(),'/') | |||
local subpage = titleparts[#titleparts] | |||
return this.checkLanguage(subpage,mw.language.getContentLanguage():getCode()) | |||
end | |||
function this.checkLanguage(subpage,default) | |||
--[[Check first if there's an apostrophe, because they break the isKnownLanguageTag | --[[Check first if there's an apostrophe, because they break the isKnownLanguageTag | ||
function. This test does not work with regexps, use plain search instead (no need | function. This test does not work with regexps, use plain search instead (no need | ||
Line 17: | Line 41: | ||
end | end | ||
-- Otherwise there's currently no known language subpage | -- Otherwise there's currently no known language subpage | ||
return | return default | ||
end | end | ||