Module:Country links: Difference between revisions

From Donate
Jump to navigation Jump to search
Content deleted Content added
No edit summary
No edit summary
Line 18: Line 18:
end
end


function p.make_donate_links( language_code, country_list )
function p.make_donate_links( frame )


local country_list = frame.args
t = {}
local t = {}
for key, value in ipairs(country_list) do
for key, value in ipairs(country_list) do
table.insert(t, {value, p.get_country_name(language_code, value)})
table.insert(t, {value, p.get_country_name(language_code, value)})
Line 35: Line 36:


return
return
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
return lang
else
return 'en'
end

end
end



Revision as of 13:28, 29 April 2023

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( frame )

	local country_list = frame.args
    local 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

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
        return lang
    else
        return 'en'
    end

end

return p