Leaguepedia | League of Legends Esports Wiki
[checked revision][checked revision]
((via Mediawiker ST3))
((via Mediawiker ST3))
Line 21: Line 21:
   
 
local p = {}
 
local p = {}
 
function p.debug(str)
 
local vars = lookup(str)
 
local tbl = {
 
'cat'
 
}
 
for k, v in pairs(vars) do
 
if type(v) == 'string' then
 
tbl[#tbl+1] = v
 
end
 
end
 
return table.concat(tbl,',')
 
end
 
   
 
function p.main(frame)
 
function p.main(frame)

Revision as of 03:05, 7 November 2018

Edit the documentation or categories for this module.


local lang = mw.getLanguage('en')
local COUNTRY_LOOKUP = mw.loadData('Module:Countrynames')
local DEFAULT = {
	name = 'Unrecognized Country![[Category:Unrecognized Country]]',
	adjective = 'Unrecognized Country![[Category:Unrecognized Country]]',
	flag = 'Unrecognized Country![[Category:Unrecognized Country]]',
	the = false
}

local function lookup(str)
	local str_lc = lang:lc(str)
	local vars = COUNTRY_LOOKUP[str_lc]
	if not vars then
		return DEFAULT
	end
	if type(vars) == 'string' then
		vars = COUNTRY_LOOKUP[vars]
	end
	return vars
end

local p = {}

function p.main(frame)
	local args = frame
	if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end
	
	if not args[1] or args[1] == '' then
		return ''
	end
	local style = args[2] or 'default'
	
	return p[style](args[1])
end

function p.default(str)
	local vars = lookup(str)
	return vars.name
end

function p.rightlong(str)
	local vars = lookup(str)
	if vars.flag then
		return string.format('[[File:%s.png|%s|link=]] %s',
			vars.flag,
			vars.name,
			vars.name
		)
	end
	return vars.name
end

function p.localization(str)
	local vars = lookup(str)
	return vars.adjective
end

function p.onlyimage(str)
	local vars = lookup(str)
	return vars.flag and string.format(
		'[[File:%s.png|%s|link=]]',
		vars.flag,
		vars.name
	) or ''
end

function p.namethe(str)
	local vars = lookup(str)
	return (vars.the and 'the ' or '') .. (vars.name or '')
end

return p