Leaguepedia | League of Legends Esports Wiki
[checked revision][checked revision]
((via Mediawiker ST3))
((via Mediawiker ST3))
Line 1: Line 1:
  +
local lang = mw.getLanguage('en')
 
local LOOKUP = mw.loadData('Module:Countrynames')
 
local LOOKUP = mw.loadData('Module:Countrynames')
 
local DEFAULT = {
 
local DEFAULT = {
Line 8: Line 9:
   
 
function lookup(str)
 
function lookup(str)
local lc = str:lower()
+
local lc = lang:lc(str)
 
local vars = LOOKUP[lc]
 
local vars = LOOKUP[lc]
 
if not vars then
 
if not vars then

Revision as of 01:35, 7 November 2018

Edit the documentation or categories for this module.


local lang = mw.getLanguage('en')
local 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
}

function lookup(str)
	local lc = lang:lc(str)
	local vars = LOOKUP[lc]
	if not vars then
		return DEFAULT
	end
	if type(vars) == 'string' then
		vars = 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