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
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({
'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 )
page = p2▼
local infobox_name = frame.args.infobox
local language = frame.args.language
page = p3▼
local country = frame.args.country
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
if ( country == 'US' ) then
page = mw.title.new( 'Template:Tax/LinkOnly' )
else
'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
else
end
end
|