Minecraft Wiki
BSkyWcloud (토론 | 기여)
(중국어 판으로 갈아 엎었습니다. 잘 되어야 할텐데...)
편집 요약 없음
6번째 줄: 6번째 줄:
 
local exclusive = mw.loadData( 'Module:Autolink/Exclusive' )
 
local exclusive = mw.loadData( 'Module:Autolink/Exclusive' )
 
local colors = { 'white ', 'orange ', 'magenta ', 'light blue ', 'yellow ', 'lime ', 'pink ', 'gray ', 'light gray ', 'cyan ', 'purple ', 'blue ', 'brown ', 'green ', 'red ', 'black ', 'silver ' }
 
local colors = { 'white ', 'orange ', 'magenta ', 'light blue ', 'yellow ', 'lime ', 'pink ', 'gray ', 'light gray ', 'cyan ', 'purple ', 'blue ', 'brown ', 'green ', 'red ', 'black ', 'silver ' }
local colorc = { '하얀색', '주황색', '자홍색', '하늘색', '노란색', '연두색', '분홍색', '회색', '회백색', '청록색', '보라색', '파란색', '갈색', '초록색', '빨간색', '검은색', '회백색'}
+
local colorc = { '하얀색', '주황색', '자홍색', '하늘색', '노란색', '연두색', '분홍색', '회색', '회백색', '청록색', '보라색', '파란색', '갈색', '초록색', '빨간색', '검은색', '은색'}
   
 
local function Set (list)
 
local function Set (list)

2019년 1월 9일 (수) 08:24 판

Autolink(자동번역) 모듈은 틀 내의 게임 아이템 이름을 자동으로 번역해줍니다. 용어 번역용인 만큼 영어 위키는 사용하지 않으며, 유지보수 시 보통 일본판 코드를 참조합니다.

쓰임새

  • {{BlockLink}}, {{ItemLink}} 등에서 아이템 이름을 영어로 입력했을 때 결과물이 한국어로 변환됩니다.
  • 모듈 입력값은 영어지만 출력값이 한국어여야 할 때 사용됩니다.

같이 보기

[보기 | 편집 | 역사 | 캐시 제거]위 설명문서는 모듈:Autolink/doc에서 왔습니다.
local p = {}

local block = mw.loadData( 'Module:Autolink/Block' )
local item = mw.loadData( 'Module:Autolink/Item' )
local other = mw.loadData( 'Module:Autolink/Other' )
local exclusive = mw.loadData( 'Module:Autolink/Exclusive' )
local colors = { 'white ', 'orange ', 'magenta ', 'light blue ', 'yellow ', 'lime ', 'pink ', 'gray ', 'light gray ', 'cyan ', 'purple ', 'blue ', 'brown ', 'green ', 'red ', 'black ', 'silver ' }
local colorc = { '하얀색', '주황색', '자홍색', '하늘색', '노란색', '연두색', '분홍색', '회색', '회백색', '청록색', '보라색', '파란색', '갈색', '초록색', '빨간색', '검은색', '은색'}

local function Set (list)
	local set = {}
	for _, l in ipairs(list) do set[l] = true end
	return set
end

local coloredItems = Set { 'firework star', 'hardened clay', 'stained clay', 'banner', 'carpet', 'concrete', 'concrete powder', 'glazed terracotta', 'terracotta', 'shield', 'shulker box', 'stained glass', 'stained glass pane', 'wool', 'bed', 'hardened glass', 'hardened stained glass', 'balloon', 'glow stick', 'hardened glass pane', 'hardened glass', 'sparkler' }

-- used by templates, called via #invoke
function p.link( f )
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	end
	return p.invlink( args[1] , args[2] , args[3] )
end

function p.invlink( str , mode, type )
	local arg = string.lower(string.gsub(str , "-" , " "))
	-- check for spawn egg
	if string.find(arg, ' spawn egg', -10, true) then
		local mob = other['EntitySprite'][string.sub(arg, 0, -11)]
		if mob == nil then
			error('missing mob entry: ' .. string.sub(arg, 0, -11))
		end
		index = string.find(mob, '|', 0, true)
		if index then
			mob = string.sub(mob, index+1)
		end
		return p.mode('刷怪蛋|' .. mob .. '刷怪蛋', mode)
	end

	local be
	local lce
	-- check for version postfix
	if string.sub(arg, -3) == ' pe' or string.sub(arg, -3) == ' be' then
		be = 1
		arg = string.sub(arg, 0, -4)
	end
	if string.sub(arg, -4) == ' lce' then
		lce = 1
		arg = string.sub(arg, 0, -5)
	end
	-- check for color prefix
	local color
	for i, c in ipairs( colors ) do
		if string.find(arg, c) == 1 then
			local item = string.sub(arg, string.len(c)+1)
			if coloredItems[item] then
				color = colorc[i]
				arg = item
			end
	   end
	end
	local result
	if type and other[type] then
		result = other[type][arg]
	end
	if result == nil then
		result = block[arg] or item[arg]
	end 
	if result == nil and string.sub(arg, -1) == 's' then
		local singular = string.sub(arg, 0, -2)
		result = block[singular] or item[singular]
	end
	if result == nil then
		for _, list in pairs( other ) do
			result = list[arg]
			if result then
				break
			end
		end
	end

	if result == nil then
		result = exclusive[arg] or str
	end
	
	if color then
		result = result .. '|' .. color .. result   
	end

	if be then
		return p.mode(result, mode, '(베드락)')
	end
	if lce then
		return p.mode(result, mode, '(교육용)')
	end

	return p.mode(result, mode)
end

function p.mode( str , mode , postfix )
	if postfix then
		str = str .. '|' .. str .. postfix
	end
	index = string.find(str, '|', 0, true)
	-- return the translated part
	if index then
		if mode == 'nolink' then 
		  return string.sub(str, index+1)
		end
		-- return the page link part
		if mode == 'linkonly' then
			return string.sub(str, 1 , index-1)
		end
	end
	return str
end

-- list out all entries with the type
function p.list( f )
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	end
	local type = args[1]
	type = string.lower(type)

	local list = nil
	if type == 'block' then
		list = block
	end
	if type == 'item' then
		list = item
	end
	if list == nil then
		return ''
	end
	local result = ''
	local t = {}
	
	for k,_ in pairs(list) do
		table.insert(t, k)
	end
	
	table.sort(t)
	
	local limit = 50
	local count = 0
	
	local table = nil
	local header = mw.html.create('tr')
	header:tag('th'):wikitext('영어 명칭')
	header:tag('th'):wikitext('한글 명칭')
	
	for _,v in ipairs(t) do
		if count == 0 then 
			if table ~= nil then
				result = result .. tostring(table)
			end
			table = mw.html.create('table'):attr('align', 'left'):css('float', 'left'):css('margin', '2px'):css('border', '1px solid silver'):css('text-align', 'center'):css('background-color', '#fff'):node(header)
		end
	
		local row = mw.html.create('tr')
		row:tag('td'):wikitext((v:gsub('(%l)(%w*)', function(a,b) return a:upper()..b end)))
		row:tag('td'):wikitext(p.mode(list[v], 'nolink'))
		table:node(row)
		count = count + 1
		if count == limit then
			count = 0
		end
	end
	
	result = result .. tostring(table)
	return result
end

return p