Module:Sandbox: Difference between revisions

Content deleted Content added
escape special character
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1:
local p = {} -- p stands for package
 
-- supported languages
function p.get_appeal( frame )
local lang_list = { 'ca', 'da', 'de', 'es', 'es-419', 'fr', 'he', 'hu', 'it', 'ja', 'lv', 'nb', 'nl', 'pl', 'pt', 'pt-br', 'ro', 'ru', 'sk', 'sv', 'uk', 'zh-hans' }
 
function p.get_appealget_langlinks( frame )
local appeal_name = string.gsub( frame.args.appeal , 'Appeal%-', '' )
local language = frame.args.language
local country = frame.args.country
 
local output = '<ul>'
local p1 = mw.title.new( 'Template:Appeal/' .. appeal_name .. '/' .. language .. '/' .. country )
local root = 'Problems donating'
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 )
 
output = output .. string.format('<li lang="en" style="white-space: nowrap;">[[%s|English]]</li>', root)
if p1.exists then
 
page = p1
for i, lang in ipairs(lang_list) do
elseif p2.exists then
pagelocal title = p2root .. '/' .. lang
local p = mw.title.new( title )
elseif p3.exists then
pageif =p.exists p3then
local lang_name = mw.language.fetchLanguageName( lang )
else
output = output .. string.format('<li lang="%s" style="white-space: nowrap;">[[%s|%s]]</li>', lang, title, lang_name)
page = p4
page = p1end
end
 
output = output .. '</ul>'
local expanded = frame:expandTemplate{ title = page, args = { } }
return expandedoutput
 
end
return expanded
 
function p.get_langtable( frame )
 
local output = ''
 
for i, lang in ipairs(lang_list) do
local lang_name = mw.language.fetchLanguageName( lang )
local row = string.format([==[
|-
! scope="row" | %s
| [[Thank You/%s]]
| [[Ways to Give/%s]]
| [[Problems donating/%s]]
| [[Cancel or change recurring giving/%s]]
| [[Matching Gifts/%s]]
| [[FAQ/%s]]
| [[Tax deductibility/%s]]
]==], lang_name, lang, lang, lang, lang, lang, lang, lang)
output = output .. row
elseend
 
return output
 
end
 
country_names_data = mw.loadJsonData( 'User:Pcoombe/sandbox.json' )
 
function p.get_country_name( language_code, country_code )
 
local name = country_names_data[language_code][country_code]
return name
 
end
 
function p.make_donate_link( 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
local link_text = p.get_country_name( language_code, country_code )
local link = '[' .. url .. ' ' .. link_text .. ']'
 
return link
 
end