모듈:Video game release

L위키, 시민들이 참여하여 가꾸는 리버럴 위키
require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local cd = require('Module:CountryData')
local list = require('Module:List');
local p = {}

local labels  = {
    ['NA'] = "[[북아메리카|북미]]",
    ['EU'] = "[[유럽]]",
    ['EUR'] = "[[유럽]]",
    ['AU'] = "[[오스트레일리아|호주]]",
    ['AUS'] = "[[오스트레일리아|호주]]",
    ['PAL'] = "[[PAL 지역|PAL]]",
    ['SEA'] = "[[동남아시아|동남아]]",
    ['AS'] = "[[아시아]]",
    ['SA'] = "[[남아메리카|남미]]",
    ['INT'] = "<abbr title=\"국제판\">국제</abbr>",
    ['WW'] = "전 세계",
    ['JP'] = "[[일본]]",
    ['KR'] = "[[대한민국|한국]]",
    ['CN'] = "[[중화인민공화국|중국]]",
    ['TW'] = "[[중화민국|대만]]",
    ['HK'] = "[[홍콩]]",
    ['UK'] = "[[영국]]",
    ['US'] = "[[미국]]",
    ['CA'] = "[[캐나다]]",
    ['NZ'] = "[[뉴질랜드]]",
    ['NZL'] = "[[뉴질랜드]]",
    ['?'] = "<abbr title=\"알 수 없음\">?</abbr>"
}

local function getLocalLabel(alias)
	local label = labels[string.upper(alias)] 

	return label
end

local countryData = {}; -- Used to store country data to avoid the need of repeated calls to Module:CountryData. This saves a little time if the same abbreviation appears multiple times in the template.

local function getCountryData(frame, alias)
	local ualias = string.upper(alias)
	
	if(countryData[ualias] == nil) then
		local cdtable = cd.gettable(frame,alias,{})
		countryData[ualias] = cdtable['alias']
	end

	return countryData[ualias]
end

function p.main(frame)
	local args = getArgs(frame)
	local listformat = args['format']
	if(listformat == nil or listformat == "") then
		listformat = "unbulleted"
	end
	local items = {}
	
	-- Old syntax "Two parameter region" use case, where param 1 is an article, param 2 is a label, and param 3 is the date. We assume this case if argument 4 is nil.
	if(args[3] ~= nil and args[4] == nil) then
		local item = "<span style=\"font-size:95%;\">[["
		if(args[1] ~= nil) then
			item = item .. args[1]
		end
		item = item .. "|"
		if(args[2] ~= nil) then
			item = item .. args[2]
		end
		item = item .. "]]:</span> " .. args[3] .. "[[분류:두 개의 변수 지역 없이 vgarelease가 쓰인 글]]"
		table.insert(items, item)
	-- Old syntax "Blank region" use case, where param 1 is empty, and param 2 is the date.
	elseif(args[1] == nil and args[2] ~= nil) then
		local item = args[2] .. "[[분류:지역 없이 vgrelease가 쓰인 글]]"
		table.insert(items, item)
	-- Normal use cases, region/date pairs in 1/2, 3/4, 5/6, etc.
	else
		local i = 1
		local j = 2
	    while(args[i] and args[j]) do
    		local label = getLocalLabel(args[i]);
    	
	    	-- Didn't find a local label? Check for country data.
    		if(label == nil) then
    			label = getCountryData(frame, args[i])
    		
	    		-- Found something? Build a sitelink with it.
    			if(label ~= nil) then
    				label = "[[" .. label .. "|" .. args[i] .. "]]"
    			else
	    			label = args[i]
				end
			end

			local item = "<span style=\"font-size:95%;\">" .. label .. ":</span> " .. args[j]
			table.insert(items, item)
      
			i = i + 2
			j = j + 2
		end
    end

	local out = list.makeList(listformat, items)

	-- Set message for invalid parameters. Decide catagory based on list format chosen.
	local parameterMsg
	if(listformat == "horizontal") then
		parameterMsg = "[[분류:명명된 변수 없이 vgarelease hlist가 쓰인 글|_VALUE_]]"
	else
		parameterMsg = "[[분류:명명된 변수 없이 vgarelease가 쓰인 글|_VALUE_]]"
	end
	
	-- Preview message.
 	if(frame:preprocess( "{{REVISIONID}}" ) == "") then
		parameterMsg = "<div class=\"hatnote\" style=\"color:red\"><strong>경고:</strong> 알 수 없는 변수 \"_VALUE_\" (이 메시지는 미리 보기에서만 표시됩니다).</div>"
	end
	
    -- Check for named parameters	
	for k, v in pairs(args) do
		if(type(k) ~= 'number' and k ~= 'format') then
			local msg = parameterMsg:gsub('_VALUE_', k)
			out = out .. msg
		end
	end

    return out
end

return p