Minecraft Wiki
잔글편집 요약 없음
잔글 (일본판에 맞게 코드 업데이트)
 
(같은 사용자의 중간 판 16개는 보이지 않습니다)
1번째 줄: 1번째 줄:
 
local p = {}
 
local p = {}
   
local block = mw.loadData( 'Module:Autolink/Block' )
+
local block = mw.loadData( '모듈:Autolink/Block' )
local item = mw.loadData( 'Module:Autolink/Item' )
+
local item = mw.loadData( '모듈:Autolink/Item' )
local other = mw.loadData( 'Module:Autolink/Other' )
+
local other = mw.loadData( '모듈:Autolink/Other' )
  +
local exclusive = mw.loadData( '모듈:Autolink/Exclusive' )
local colors = { 'white ', 'orange ', 'magenta ', 'light blue ', 'yellow ', 'lime ', 'pink ', 'gray ', 'light gray ', 'cyan ', 'purple ', 'blue ', 'brown ', 'green ', 'red ', 'black ' }
 
  +
local earth = mw.loadData( '모듈:Autolink/Earth' )
local colorc = { '하얀색 ', '주황색 ', '자홍색 ', '하늘색 ', '노란색 ', '연두색 ', '분홍색 ', '회색 ', '회백색 ', '청록색 ', '보라색 ', '파란색 ', '갈색 ', '초록색 ', '빨간색 ', '검은색 ' }
 
  +
local dungeons = mw.loadData( '모듈:Autolink/Dungeons' )
  +
local colors = {
  +
['black '] = '검은색 ',
  +
['blue '] = '파란색 ',
  +
['brown '] = '갈색 ',
  +
['cyan '] = '청록색 ',
  +
['gray '] = '회색 ',
  +
['green '] = '초록색 ',
  +
['light blue '] = '하늘색 ',
  +
['light gray '] = '회백색 ',
  +
['lime '] = '연두색 ',
  +
['magenta '] = '자홍색 ',
  +
['orange '] = '주황색 ',
  +
['pink '] = '분홍색 ',
  +
['purple '] = '보라색 ',
  +
['red '] = '빨간색 ',
  +
['silver '] = '회백색 ',
  +
['white '] = '하얀색 ',
  +
['yellow '] = '노란색 ',
  +
}
  +
   
 
local function Set (list)
 
local function Set (list)
local set = {}
+
local set = {}
for _, l in ipairs(list) do set[l] = true end
+
for _, l in ipairs(list) do set[l] = true end
return set
+
return set
 
end
 
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' }
+
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', 'candle' }
   
  +
-- used by templates, called via #invoke
 
function p.link( f )
 
function p.link( f )
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
+
args = require( '모듈:ProcessArgs' ).merge( true )
 
end
 
end
local arg = args[1]
+
return p.invlink( args[1] , args[2] , args[3] )
arg = string.lower(arg)
 
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 = block[arg]
 
if result == nil then
 
result = item[arg]
 
end
 
if result == nil then
 
--check for spawn egg
 
if not string.find(arg, ' spawn egg', -10, true) then
 
result = other[arg]
 
else
 
local mob = other[string.sub(arg,0,-11)]
 
if mob == nil then
 
error('존재하지 않는 몹 엔트리: "' .. string.sub(arg, 0, -11) .. '" (입력받은 문자열: "' .. arg ..'")')
 
end
 
index = string.find(mob,'|',0,true)
 
if index then
 
mob = string.sub(mob, index+1)
 
end
 
result = mob .. " 생성 알"
 
end
 
end
 
local index
 
if result == nil then
 
result = args[1]
 
index = string.find(result,'|',0,true)
 
else
 
if color then
 
result = result .. '|' .. color .. result
 
end
 
index = string.find(result,'|',0,true)
 
if pe then
 
if index then
 
result = result .. '(포켓 에디션)'
 
else
 
result = result .. '|' .. result .. '(포켓 에디션)'
 
end
 
end
 
end
 
local mode = args[2]
 
if mode and index then
 
-- return the fully translated part
 
if mode == 'nolink' then
 
result = string.sub(result, index+1)
 
end
 
-- return the page link part
 
if mode == 'linkonly' then
 
result = string.sub(result, 1 , index-1)
 
end
 
end
 
return result
 
 
end
 
end
   
function p.xlink( str , mode )
+
function p.invlink( str , mode, type )
  +
local arg = str:gsub("-" , " "):lower()
if str == nil then
 
  +
-- check for spawn egg
return nil
 
  +
if arg:find ' spawn egg$' then
end
 
local arg = string.lower(str)
+
local mob = other['EntitySprite'][arg:sub(0, -11)]
if mode == nil then
+
if mob == nil then
  +
error('missing mob entry: ' .. arg:sub(0, -11))
mode = 'default'
 
end
+
end
  +
local index = mob:find '|'
local pe
 
  +
if index then
if string.sub(arg, -3) == ' pe' then
 
  +
mob = mob:sub(index + 1)
pe = 1
 
  +
end
arg = string.sub(arg, 0, -4)
 
  +
return p.mode('생성 알|' .. mob .. ' 생성 알', mode)
end
 
  +
end
local color
 
  +
for i, c in ipairs( colors ) do
 
  +
local be
if string.find(arg, c) == 1 then
 
  +
local lce
local item = string.sub(arg, string.len(c)+1)
 
  +
-- check for version postfix
if coloredItems[item] then
 
  +
if arg:find ' pe$' or arg:find ' be$' then
color = colorc[i]
 
  +
be = 1
arg = item
 
  +
arg = arg:sub(0, -4)
end
 
end
+
end
  +
if arg:find ' lce$' then
end
 
  +
lce = 1
local result = block[arg]
 
  +
arg = arg:sub(0, -5)
if result == nil then
 
  +
end
result = item[arg]
 
  +
end
 
  +
-- check for 'spawn'
if result == nil then
 
  +
if arg:find '^spawn' then
--check for spawn egg
 
  +
local mob = other['EntitySprite'][arg:sub(7)]
if not string.find(arg, ' spawn egg', -10, true) then
 
  +
if mob then
result = other[arg]
 
  +
local index = mob:find '|'
else
 
  +
if index then
local mob = other[string.sub(arg,0,-11)]
 
  +
mob = mob:sub(index + 1)
if mob == nil then
 
  +
end
error('존재하지 않는 몹 엔트리: "' .. string.sub(arg, 0, -11) .. '" (입력받은 문자열: "' .. arg ..'")')
 
  +
local name = '생성 알|생성 ' .. mob
end
 
  +
if be then
index = string.find(mob,'|',0,true)
 
  +
return p.mode(name, mode, '(Bedrock Edition)')
if index then
 
  +
end
mob = string.sub(mob, index+1)
 
  +
if lce then
end
 
  +
return p.mode(name, mode, '(Legacy Console Edition)')
result = mob .. " 생성 알"
 
end
+
end
  +
return p.mode(name, mode)
end
 
  +
end
local index
 
  +
end
if result == nil then
 
  +
result = str
 
  +
-- check for color prefix
index = string.find(result,'|',0,true)
 
  +
local color
else
 
  +
for k, v in pairs( colors ) do
if color then
 
  +
if arg:find(k) == 1 then
result = result .. '|' .. color .. result
 
  +
local i = arg:sub(k:len() + 1)
end
 
  +
if coloredItems[i] then
index = string.find(result,'|',0,true)
 
  +
color = v
if pe then
 
  +
arg = i
if index then
 
  +
break
result = result .. '(포켓 에디션)'
 
  +
end
else
 
  +
end
result = result .. '|' .. result .. '(포켓 에디션)'
 
  +
end
index = string.find(result,'|',0,true)
 
  +
local result
end
 
  +
if type and other[type] then
end
 
  +
result = other[type][arg]
end
 
  +
end
 
if index then
+
if result == nil and type and earth[type] then
  +
result = earth[type][arg]
-- return the fully translated part
 
  +
end
if mode == 'nolink' then
 
  +
if result == nil and type and dungeons[type] then
result = string.sub(result, index+1)
 
  +
result = dungeons[type][arg]
end
 
  +
end
-- return the page link part
 
if mode == 'linkonly' then
+
if result == nil and type and type == 'ItemSprite' then
  +
result = item[arg]
result = string.sub(result, 1 , index-1)
 
end
+
end
  +
if result == nil then
end
 
  +
result = block[arg] or item[arg]
return result
 
  +
end
  +
if result == nil and arg:sub(-1) == 's' then
  +
local singular = arg:sub(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
  +
for _, list in pairs( dungeons ) 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, suffix )
  +
if suffix then
  +
if str:find '|' then
  +
str = str .. suffix
  +
else
  +
str = str .. '|' .. str .. suffix
  +
end
  +
end
  +
local index = str:find '|'
  +
-- return the translated part
  +
if index then
  +
if mode == 'nolink' then
  +
return str:sub(index + 1)
  +
end
  +
-- return the page link part
  +
if mode == 'linkonly' then
  +
return str:sub(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( '모듈:ProcessArgs' ).merge( true )
  +
end
  +
local type = args[1]
  +
type = type:lower()
  +
local sprite = nil
  +
local list = nil
  +
if type == 'block' then
  +
list = block
  +
sprite = 'BlockSprite'
  +
elseif type == 'item' then
  +
list = item
  +
sprite = 'ItemSprite'
  +
elseif type == 'entity' then
  +
list = other['EntitySprite']
  +
sprite = 'EntitySprite'
  +
elseif type == 'dungeonsitem' then
  +
list = dungeons['DungeonsItemSprite']
  +
sprite = 'DungeonsItemSprite'
  +
elseif type == 'dungeonsentity' then
  +
list = dungeons['DungeonsEntitySprite']
  +
sprite = 'DungeonsEntitySprite'
  +
elseif type == 'dungeonsenchantment' then
  +
list = dungeons['DungeonsEnchantmentSprite']
  +
sprite = 'DungeonsEnchantmentSprite'
  +
elseif type == 'dungeonslevel' then
  +
list = dungeons['DungeonsLevelSprite']
  +
sprite = 'DungeonsLevelSprite'
  +
end
  +
if list == nil then
  +
return ''
  +
end
  +
  +
local spriteids = mw.loadData( '모듈:' .. sprite ).ids
  +
  +
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 frame = mw.getCurrentFrame()
  +
  +
local table = nil
  +
local header = mw.html.create('tr')
  +
header:tag('th'):wikitext('아이콘')
  +
header:tag('th'):wikitext('영어 명칭')
  +
header:tag('th'):wikitext('한국어 명칭')
  +
  +
for _, v in ipairs(t) do
  +
if count == 0 then
  +
if itemlist ~= nil then
  +
result = result .. tostring(itemlist)
  +
end
  +
itemlist = mw.html.create('table')
  +
:css{
  +
float = 'left',
  +
margin = '2px',
  +
border = '1px solid silver',
  +
['text-align'] = 'center',
  +
['background-color'] = '#fff'
  +
}
  +
:node(header)
  +
end
  +
  +
local row = mw.html.create('tr')
  +
if spriteids[v] or spriteids[mw.ustring.lower( v ):gsub( '[%s%+]', '-' )] then
  +
row:tag('td'):wikitext(frame:expandTemplate{ title = sprite, args = { v } })
  +
else
  +
row:tag('td')
  +
end
  +
local words = {}
  +
v:gsub('[^%s]+', function(w) table.insert(words, w) end)
  +
for k, w in ipairs(words) do
  +
if w ~= 'of' and w ~= 'or' and w ~= 'o\'' then
  +
words[k] = w:gsub('(%l)(.+)', function(a, b) return a:upper() .. b end)
  +
end
  +
end
  +
row:tag('td'):wikitext(tostring(table.concat(words, ' ')))
  +
row:tag('td'):wikitext(p.mode(list[v], 'nolink'))
  +
itemlist:node(row)
  +
count = count + 1
  +
if count == limit then
  +
count = 0
  +
end
  +
end
  +
  +
result = result .. tostring(itemlist)
  +
return result
 
end
 
end
   

2022년 11월 28일 (월) 12:26 기준 최신판

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

쓰임새

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

같이 보기

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

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


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', 'candle' }

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

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

	local be
	local lce
	-- check for version postfix
	if arg:find ' pe$' or arg:find ' be$' then
		be = 1
		arg = arg:sub(0, -4)
	end
	if arg:find ' lce$' then
		lce = 1
		arg = arg:sub(0, -5)
	end

	-- check for 'spawn'
	if arg:find '^spawn' then
		local mob = other['EntitySprite'][arg:sub(7)]
		if mob then
			local index = mob:find '|'
			if index then
				mob = mob:sub(index + 1)
			end
			local name = '생성 알|생성 ' .. mob
			if be then
				return p.mode(name, mode, '(Bedrock Edition)')
			end
			if lce then
				return p.mode(name, mode, '(Legacy Console Edition)')
			end
			return p.mode(name, mode)
		end
	end

	-- check for color prefix
	local color
	for k, v in pairs( colors ) do
		if arg:find(k) == 1 then
			local i = arg:sub(k:len() + 1)
			if coloredItems[i] then
				color = v
				arg = i
				break
			end
		end
	end
	local result
	if type and other[type] then
		result = other[type][arg]
	end
	if result == nil and type and earth[type] then
		result = earth[type][arg]
	end
	if result == nil and type and dungeons[type] then
		result = dungeons[type][arg]
	end
	if result == nil and type and type == 'ItemSprite' then
		result = item[arg]
	end
	if result == nil then
		result = block[arg] or item[arg]
	end
	if result == nil and arg:sub(-1) == 's' then
		local singular = arg:sub(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
		for _, list in pairs( dungeons ) 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, suffix )
	if suffix then
		if str:find '|' then
			str = str .. suffix
		else
			str = str .. '|' .. str .. suffix
		end
	end
	local index = str:find '|'
	-- return the translated part
	if index then
		if mode == 'nolink' then
			return str:sub(index + 1)
		end
		-- return the page link part
		if mode == 'linkonly' then
			return str:sub(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( '모듈:ProcessArgs' ).merge( true )
	end
	local type = args[1]
	type = type:lower()
	local sprite = nil
	local list = nil
	if type == 'block' then
		list = block
		sprite = 'BlockSprite'
	elseif type == 'item' then
		list = item
		sprite = 'ItemSprite'
	elseif type == 'entity' then
		list = other['EntitySprite']
		sprite = 'EntitySprite'
	elseif type == 'dungeonsitem' then
		list = dungeons['DungeonsItemSprite']
		sprite = 'DungeonsItemSprite'
	elseif type == 'dungeonsentity' then
		list = dungeons['DungeonsEntitySprite']
		sprite = 'DungeonsEntitySprite'
	elseif type == 'dungeonsenchantment' then
		list = dungeons['DungeonsEnchantmentSprite']
		sprite = 'DungeonsEnchantmentSprite'
	elseif type == 'dungeonslevel' then
		list = dungeons['DungeonsLevelSprite']
		sprite = 'DungeonsLevelSprite'
	end
	if list == nil then
		return ''
	end

	local spriteids = mw.loadData( '모듈:' .. sprite ).ids

	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 frame = mw.getCurrentFrame()
	
	local table = nil
	local header = mw.html.create('tr')
    header:tag('th'):wikitext('아이콘')
	header:tag('th'):wikitext('영어 명칭')
	header:tag('th'):wikitext('한국어 명칭')

	for _, v in ipairs(t) do
		if count == 0 then
			if itemlist ~= nil then
				result = result .. tostring(itemlist)
			end
			itemlist = mw.html.create('table')
				:css{
					float = 'left',
					margin = '2px',
					border = '1px solid silver',
					['text-align'] = 'center',
					['background-color'] = '#fff'
				}
				:node(header)
		end

		local row = mw.html.create('tr')
		if spriteids[v] or spriteids[mw.ustring.lower( v ):gsub( '[%s%+]', '-' )] then
			row:tag('td'):wikitext(frame:expandTemplate{ title = sprite, args = { v } })
		else
			row:tag('td')
		end
		local words = {}
		v:gsub('[^%s]+', function(w) table.insert(words, w) end)
		for k, w in ipairs(words) do
			if w ~= 'of' and w ~= 'or' and w ~= 'o\'' then
				words[k] = w:gsub('(%l)(.+)', function(a, b) return a:upper() .. b end)
			end
		end
		row:tag('td'):wikitext(tostring(table.concat(words, ' ')))
		row:tag('td'):wikitext(p.mode(list[v], 'nolink'))
		itemlist:node(row)
		count = count + 1
		if count == limit then
			count = 0
		end
	end

	result = result .. tostring(itemlist)
	return result
end

return p