Module:Main: Difference between revisions

Content deleted Content added
add final fallback to Template:Appeal/default/en
refactor to use a shared fallback_pages function
 
(8 intermediate revisions by the same user not shown)
Line 2:
 
local p = {} -- p stands for package
 
-- Given an array of titles as strings, check them in order and return the first page which exists
function p.fallback_pages( list )
for key, value in ipairs( list ) do
local p5p = mw.title.new( 'Template:Appeal/default/en'value )
if p1p.exists then
return p
end
end
end
 
function p.get_appeal( frame )
Line 8 ⟶ 18:
local language = frame.args.language
local country = frame.args.country
local page = p.fallback_pages({
local p1 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/' .. language .. '/' .. country ),
local p2 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/' .. language ),
local p3 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/en' ),
local p4 = mw.title.new( 'Template:Appeal/default/' .. language ),
'Template:Appeal/default/en'
})
 
local expanded = frame:expandTemplate{ title = page, args = frame.args }
local p1 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/' .. language .. '/' .. country )
return expanded
local p2 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/' .. language )
local p3 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/en' )
local p4 = mw.title.new( 'Template:Appeal/default/' .. language )
local p5 = mw.title.new( 'Template:Appeal/default/en' )
 
end
if p1.exists then
 
page = p1
function p.get_infobox( frame )
elseif p2.exists then
 
page = p2
local infobox_name = frame.args.infobox
elseif p3.exists then
local language = frame.args.language
page = p3
local country = frame.args.country
elseif p4.exists then
page = p4
local page = p.fallback_pages({
'Template:Infobox/' .. infobox_name .. '/' .. language .. '/' .. country,
'Template:Infobox/' .. infobox_name .. '/' .. language,
'Template:Infobox/' .. infobox_name .. '/en',
'Template:Infobox/Default/' .. language,
'Template:Infobox/Default/en'
})
 
local expanded = frame:expandTemplate{ title = page, args = frame.args }
return expanded
 
end
 
function p.get_tax_message( frame )
 
local tax_message = frame.args.tax_message
local language = frame.args.language
local country = frame.args.country
local page = p1
 
if ( country == 'US' ) then
page = mw.title.new( 'Template:Tax/LinkOnly' )
else
page = p5p.fallback_pages({
'Template:Tax/' .. tax_message .. '/' .. language, -- custom message
'Template:Tax/' .. country .. '/' .. language, -- special countries e.g. FR/NL
'Template:Tax/Default/' .. language,
'Template:Tax/LinkOnly'
})
end
 
Line 30 ⟶ 72:
return expanded
end
 
function p.page_language( frame )
 
local full_title = mw.title.getCurrentTitle().prefixedText
local t = mw.text.split( full_title, '/' )
local lang = t[#t]
 
if mw.language.isKnownLanguageTag( lang ) then
pagereturn = p2lang
else
pagereturn = p3'en'
end
 
end