Autolink、つまり自動リンクモジュールは、モジュール:Reverselinkが日本語のパラメータを英語に変換し、テンプレートに提供して画像を表示するように、テンプレートのパラメータ内の英語を対応する日本語に変換して表示するために使用されるものです。
このモジュールは、主に次の目的で使用されます。
- スプライトテンプレートおよびリンク支援テンプレートのパラメータを日本語に変換し、対応するサムネイルや名称を表示する
- このWikiで表示されるゲーム内の英語名を正しい翻訳(Java Editionに基づく)に変換する
このモジュールでは、以下の下位ページに格納されているデータを使用しています。
[閲覧 | 編集 | 履歴 | キャッシュ破棄]上記の解説は、モジュール: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 colors = { 'white ', 'orange ', 'magenta ', 'light blue ', 'yellow ', 'lime ', 'pink ', 'gray ', 'light gray ', 'cyan ', 'purple ', 'blue ', 'brown ', 'green ', 'red ', 'black ' }
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' }
function p.link( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
end
local arg = args[1]
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 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
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 .. ' (Pocket Edition)'
else
result = result .. '|' .. result .. ' (Pocket Edition)'
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
function p.xlink( str , mode )
if str == nil then
return nil
end
local arg = string.lower(str)
if mode == nil then
mode = 'default'
end
local pe
if string.sub(arg, -3) == ' pe' then
pe = 1
arg = string.sub(arg, 0, -4)
end
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 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
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 .. ' (Pocket Edition)'
else
result = result .. '|' .. result .. ' (Pocket Edition)'
end
end
end
if 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
return p