Module:Country links

Revision as of 13:20, 29 April 2023 by Pcoombe (talk | contribs)

Documentation for this module may be created at Module:Country links/doc

local p = {}
local country_names_data = mw.loadJsonData( 'Module:Country links/data.json' )

function p.get_country_name( language_code, country_code )
	local name
	if country_names_data[language_code] == nil then language_code = 'en' end
    local name = country_names_data[language_code][country_code]
    return name
end

function p.get_donate_url( language_code, country_code )

    local url = 'https://donate.wikimedia.org/wiki/Special:FundraiserLandingPage?utm_medium=Waystogive&utm_source=Waystogive&utm_campaign=C11_Waystogive'
    url = url .. '&uselang=' .. language_code
    url = url .. '&country=' .. country_code
    return url

end

function p.make_donate_links( language_code, country_list )

    t = {}
    for key, value in ipairs(country_list) do
        table.insert(t, {value, p.get_country_name(language_code, value)})
    end

    -- sort by country name
    table.sort(t, function (k1, k2) return k1[2] < k2[2] end)

    for key, value in ipairs(t) do
        local url = p.get_donate_url( language_code, value[1] )
        local link_text = value[2]
        mw.log('* [' .. url .. ' ' .. link_text .. ']')
    end

    return
end

return p