모듈:Team appearances list

-- This module implements Template:Team appearances list.
local p = {}
-- i18n support for Korean
local param_ko = {
	'국가' = 'team',
	'선수단' = 'team',
	'대회' = 'competition',
	'첫참가' = 'begin_year',
	'마지막참가' = 'end_year',
	'연속' = 'interval',
}
local data_competitions
local data_old_names
local function load_data(frame)
	-- Load data module (or its sandbox) and set variables from its exported data.
	if not data_competitions then
		frame = frame or mw.getCurrentFrame()
		local sandbox = frame:getTitle():find('연습장', 1, true) and '/연습장' or 
		local datamod = mw.loadData('모듈:Team appearances list/data' .. sandbox)
		data_competitions = datamod.competitions
		data_old_names = datamod.old_names
	end
end
local function strip_to_nil(text)
	-- If text is a string, return its trimmed content, or nil if empty.
	-- Otherwise return text (which may, for example, be nil).
	if type(text) == 'string' then
		text = text:match('(%S.-)%s*$')
	end
	return text
end
local function make_options(args)
	-- Return table of options from validated args or throw error.
	local options = {}
	local function valid_integer(name, min, max, is_optional)
		local arg = argsname
		if arg == nil or arg ==  then
			if is_optional then
				return nil
			end
			error( .. name .. ' 변수가 빠졌습니다')
		end
		arg = tonumber(arg)
		if type(arg) ~= 'number' then
			error( .. name .. ' 변수에는 숫자가 들어가야 합니다')
		end
		if math.floor(arg) ~= arg then
			error( .. name .. ' 변수에는 정수가 들어가야 합니다')
		end
		if not (min  options.end_year then
			error('end_year 변수는 begin_year 보다 앞서지 않아야 합니다')
		end
	end
	options.disqualified_year = valid_integer('disqualified_year', 1800, 2100, true)
	return options
end
local function extract_range(text)
	-- Return first (if text is a single year), or first, last if a range.
	-- The returned values are numbers.
	-- Return nothing if text is invalid.
	local year = text:match('^(%d+)$')
	if year then
		if #year == 4 then
			return tonumber(year)
		end
		return
	end
	local first, dash, last = text:match('^(%d+)(%D+)(%d+)$')
	if not (first and #first == 4) then
		return
	end
	dash = strip_to_nil(dash)
	if not (dash == '-' or dash == '–') then
		return
	end
	if #last ~= 4 then
		if #last == 2 then
			last = first:sub(1, 2) .. last
		else
			return
		end
	end
	first = tonumber(first)
	last = tonumber(last)
	if first  end_year then
				break
			elseif y >= begin_year then
				table.insert(comp_years, y)
			end
		end
	else
		end_year = end_year or (os.date('!*t').year + options.interval)
		for y = begin_year, end_year, options.interval do
			table.insert(comp_years, y)
		end
	end
	local disqualified_years = {}
	if options.disqualified_year then
		-- Input currently only allows entry of a single disqualified year.
		-- However processing works for any number of such years.
		disqualified_yearsoptions.disqualified_year = true
	end
	return comp_years, disqualified_years, competition_absences(absences or args)
end
local function gameName(year, inputName)
	-- Modifies output of display being sent back to the hlist
	--  for games that have had a name change but are still considered
	--  the same competition.
	if inputName=="World Athletics Championships" or inputName=="World Championships in Athletics" then
		if year = 1984 and year ' ..
					(absent_last and (absent_first .. '–' .. absent_last) or absent_first) ..
					)
				absent_first, absent_last = nil, nil
			end
			if y then
				local display = tostring(y)
				if y > current_year then
					display =  .. display .. 
				end
				if disqualified_yearsy then
					display =  .. display .. 
				end
				local compName = gameName(y, args.competition)
				local teamOut = teamName(y, args.team, args.competition)
				if compName == 'FIS Alpine World Ski Championships' then
					table.insert(appearances, string.format(
					'%s',
					teamOut, compName, y, display
					))
				else
					table.insert(appearances, string.format(
						'%s',
						y, compName, teamOut, display
					))
				end
			end
		end
	end
	return hlist(appearances)
end
				
function p.main(frame)
	load_data(frame)
	return p._main(frame:getParent().args)
end
return p