Minecraft Wiki
(Test)
Lukes20129 (トーク | 投稿記録)
(1.17)
(6人の利用者による、間の27版が非表示)
5行目: 5行目:
 
local other = mw.loadData( 'モジュール:Autolink/Other' )
 
local other = mw.loadData( 'モジュール:Autolink/Other' )
 
local exclusive = mw.loadData( 'モジュール:Autolink/Exclusive' )
 
local exclusive = mw.loadData( 'モジュール:Autolink/Exclusive' )
  +
local earth = mw.loadData( 'モジュール:Autolink/Earth' )
local colors = { 'white ', 'orange ', 'magenta ', 'light blue ', 'yellow ', 'lime ', 'pink ', 'gray ', 'light gray ', 'cyan ', 'purple ', 'blue ', 'brown ', 'green ', 'red ', 'black ' }
 
  +
local dungeons = mw.loadData( 'モジュール:Autolink/Dungeons' )
local colorc = { '白色', '橙色', '赤紫色', '空色', '黄色', '黄緑色', '桃色', '灰色', '薄灰色', '青緑色', '紫色', '青色', '茶色', '緑色', '赤色', '黒色' }
 
  +
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( 'モジュール:ProcessArgs' ).merge( true )
 
args = require( 'モジュール:ProcessArgs' ).merge( true )
 
end
 
end
return p.core( args[1] , args[2] )
+
return p.invlink( args[1] , args[2] , args[3] )
 
end
 
end
   
function p.xlink( str , mode )
+
function p.invlink( str, mode, type )
  +
local arg = str:gsub("-" , " "):lower()
return p.core( str, mode )
 
  +
-- 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 suffix
  +
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, '(Bedrock Edition)')
  +
end
  +
if lce then
  +
return p.mode(result, mode, '(Legacy Console Edition)')
  +
end
  +
  +
return p.mode(result, mode)
 
end
 
end
   
function p.core( str , mode )
+
function p.mode( str, mode, suffix )
  +
if suffix then
local arg = string.lower(str)
 
  +
if str:find '|' then
local pe
 
  +
str = str .. suffix
if string.sub(arg, -3) == ' pe' then
 
  +
else
pe = 1
 
  +
str = str .. '|' .. str .. suffix
arg = string.sub(arg, 0, -4)
 
end
+
end
  +
end
local color
 
  +
local index = str:find '|'
for i, c in ipairs( colors ) do
 
  +
-- return the translated part
if string.find(arg, c) == 1 then
 
  +
if index then
local item = string.sub(arg, string.len(c)+1)
 
  +
if mode == 'nolink' then
if coloredItems[item] then
 
  +
return str:sub(index + 1)
color = colorc[i]
 
  +
end
arg = item
 
  +
-- return the page link part
end
 
  +
if mode == 'linkonly' then
end
 
  +
return str:sub(1 , index - 1)
end
 
  +
end
local result = block[arg]
 
  +
end
if result == nil then
 
  +
return str
result = item[arg]
 
end
 
if result == nil then
 
--check for spawn egg
 
if string.find(arg,'spawn ',0,true) == nil or string.len(arg) < 7 then
 
result = other[arg]
 
else
 
local mob = other[string.sub(arg,7)]
 
index = string.find(mob,'|',0,true)
 
if index ~= nil then
 
mob = string.sub(mob, index+1)
 
end
 
result = "スポーンエッグ|スポーン " .. mob
 
end
 
end
 
if result == nil then
 
result = exclusive[arg]
 
end
 
local index
 
if result == nil then
 
result = str
 
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 .. ' (Bedrock Edition)'
 
else
 
result = result .. '|' .. result .. ' (Bedrock Edition)'
 
index = string.find(result,'|',0,true)
 
end
 
end
 
end
 
 
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
   
  +
-- list out all entries with the type
 
function p.list( f )
 
function p.list( f )
local args = f
+
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
 
args = require( 'モジュール:ProcessArgs' ).merge( true )
 
args = require( 'モジュール:ProcessArgs' ).merge( true )
 
end
 
end
local type = args[1]
+
local type = args[1]
type = string.lower(type)
+
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 list = nil
 
if type == 'block' then
 
list = block
 
end
 
if type == 'item' then
 
list = item
 
end
 
if type == 'other' then
 
list = other
 
end
 
if list == nil then
 
return ''
 
end
 
 
local result = ''
 
local result = ''
 
local t = {}
 
local t = {}
  +
 
for k,_ in pairs(list) do
+
for k, _ in pairs(list) do
 
table.insert(t, k)
 
table.insert(t, k)
 
end
 
end
  +
 
 
table.sort(t)
 
table.sort(t)
  +
 
 
local limit = 50
 
local limit = 50
 
local count = 0
 
local count = 0
  +
 
local table = nil
+
local frame = mw.getCurrentFrame()
  +
  +
local itemlist = nil
 
local header = mw.html.create('tr')
 
local header = mw.html.create('tr')
header:tag('th'):wikitext('英語版での名称')
+
header:tag('th'):wikitext('アイコン')
header:tag('th'):wikitext('日本版での名称')
+
header:tag('th'):wikitext('語名称')
  +
header:tag('th'):wikitext('日本語名称')
 
  +
for _,v in ipairs(t) do
 
  +
for _, v in ipairs(t) do
if count == 0 then
 
if table ~= nil then
+
if count == 0 then
  +
if itemlist ~= nil then
result = result .. tostring(table)
 
  +
result = result .. tostring(itemlist)
 
end
 
end
  +
itemlist = mw.html.create('table')
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)
 
  +
:css{
  +
float = 'left',
  +
margin = '2px',
  +
border = '1px solid silver',
  +
['text-align'] = 'center',
  +
['background-color'] = '#fff'
  +
}
  +
:node(header)
 
end
 
end
  +
 
 
local row = mw.html.create('tr')
 
local row = mw.html.create('tr')
  +
if spriteids[v] or spriteids[mw.ustring.lower( v ):gsub( '[%s%+]', '-' )] then
row:tag('td'):wikitext((v:gsub('(%l)(%w*)', function(a,b) return a:upper()..b end)))
 
row:tag('td'):wikitext(p.xlink(v, 'nolink'))
+
row:tag('td'):wikitext(frame:expandTemplate{ title = sprite, args = { v } })
  +
else
table:node(row)
 
  +
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
 
count = count + 1
 
if count == limit then
 
if count == limit then
152行目: 277行目:
 
end
 
end
 
end
 
end
  +
 
result = result .. tostring(table)
+
result = result .. tostring(itemlist)
 
return result
 
return result
 
end
 
end

2021年6月12日 (土) 10:19時点における版

Autolink、つまり自動リンクモジュールは、モジュール:Reverselinkが日本語のパラメータを英語に変換し、テンプレートに提供して画像を表示するように、テンプレートのパラメータ内の英語を対応する日本語に変換して表示するために使用されるものです。

このモジュールは、主に次の目的で使用されます。

このモジュールでは、以下の下位ページに格納されているデータを使用しています。

[閲覧 | 編集 | 履歴 | キャッシュ破棄]上記の解説は、モジュール: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 suffix
	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, '(Bedrock Edition)')
	end
	if lce then
		return p.mode(result, mode, '(Legacy Console Edition)')
	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 itemlist = 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