Module:Country links: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
Line 20: | Line 20: | ||
function p.make_donate_links( frame ) |
function p.make_donate_links( frame ) |
||
local country_list = frame.args |
|||
local language_code = p.page_language( frame ) |
local language_code = p.page_language( frame ) |
||
local t = {} |
local t = {} |
||
for key, value in ipairs( |
for key, value in ipairs(frame.args) do |
||
table.insert(t, {value, p.get_country_name(language_code, value)}) |
table.insert(t, {value, p.get_country_name(language_code, value)}) |
||
end |
end |
Revision as of 13:31, 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 language_code = p.page_language( frame )
local t = {}
for key, value in ipairs(frame.args) 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