Module:Main

From Donate
Revision as of 20:36, 5 March 2019 by Pcoombe (talk | contribs) (Created page with "-- Single utility module. Break this into separate modules if it gets too large. local p = {} -- p stands for package function p.get_appeal( frame ) local appeal_name =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation

get_appeal

Includes the best localised appeal subpage of Template:Appeal, based on appeal name, language, and country given. Also passes the parameters to the selected appeal template for their use (e.g. in localising amounts with {{AppealAmountSwitch}})

Parameters:

  • appeal - initial "Appeal-" (which was required for older links) is stripped off if present
  • language
  • country
  • Any other parameters to pass through to the appeal template (e.g. sitename)

Example:

{{#invoke:Main|get_appeal|appeal=Alan|country=CA|language=fr}}

Replaces {{2012FR/Switch/Appeal}}

get_infobox

Does basically the same thing for subpages of Template:Infobox

Replaces {{2012FR/Switch/Infobox}}

get_tax_message

Code should be fairly self explanatory. Allows overriding the default message for certain countries.

page_language

Return the language code of the current subpage. If it isn't a subpage, or isn't a valid language code, return 'en'.


-- Single utility module. Break this into separate modules if it gets too large.

local p = {} -- p stands for package

function p.get_appeal( frame )

    local appeal_name = string.gsub( frame.args.appeal , 'Appeal%-', '' )
    local language = frame.args.language
    local country = frame.args.country

    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 )

    if p1.exists then
        page = p1
    elseif p2.exists then
        page = p2
    elseif p3.exists then
        page = p3
    else
        page = p4
    end

    local expanded = frame:expandTemplate{ title = page, args = frame.args }
    return expanded
    
end

return p