956
次編輯
Economy666(留言 | 貢獻) (CALv2更新完成) |
Economy666(留言 | 貢獻) (修复无链接文本(vocal)日文显示) |
||
行 2: | 行 2: | ||
-- local mad = require 'Module:AnotherData' | -- local mad = require 'Module:AnotherData' | ||
local NotJaArtist = {['旅人E']=''} | |||
-- local NotJaVocal = {['熊子']=''} | |||
local function link(l, d) | local function link(l, d) | ||
行 10: | 行 14: | ||
end | end | ||
end | end | ||
local NotJaArtist = { | |||
local function formatLangText(text) | |||
if not text then return text end | |||
if NotJaArtist[text] then return text end | |||
return mw.ustring.gsub( | |||
text, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', | |||
function(v) return ('<span lang="ja">-{%s}-</span>'):format(v) end | |||
) | |||
end | |||
local function langLink(__link, display) | |||
if display then | |||
return link('曲师列表#' .. __link, formatLangText(display)) | |||
else | |||
return link('曲师列表#' .. __link, formatLangText(__link)) | |||
end | |||
end | |||
local function fullCAL(__FullData__) | |||
local artist = '' | |||
for _, data in ipairs(__FullData__) do | |||
local display_lang = formatLangText(data.display) | |||
if data.link then | |||
artist = artist .. langLink(data.link, data.display) | |||
else | |||
artist = artist .. (display_lang or '') | |||
end | |||
end | |||
return artist | |||
end | |||
local function defaultCAL(text, artist_list) | |||
local temp_text = text | |||
local link_placeholders = {} | |||
local placeholder_count = 0 | |||
for theLink, display in pairs(artist_list) do | |||
if type(display) == 'string' then | |||
local link_text = langLink(theLink, display) | |||
local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__" | |||
link_placeholders[placeholder] = link_text | |||
temp_text = string.gsub(temp_text, display, placeholder) | |||
placeholder_count = placeholder_count + 1 | |||
elseif type(display)=='table' then | |||
for _,dis in pairs(display) do | |||
local link_text = langLink(theLink, dis) | |||
local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__" | |||
link_placeholders[placeholder] = link_text | |||
temp_text = string.gsub(temp_text, dis, placeholder) | |||
placeholder_count = placeholder_count + 1 | |||
end | |||
end | |||
end | |||
local formatted_text = formatLangText(temp_text) | |||
for placeholder, link_text in pairs(link_placeholders) do | |||
formatted_text = string.gsub(formatted_text, placeholder, link_text) | |||
end | |||
return formatted_text | |||
end | |||
function p.artistLink(artistName) | function p.artistLink(artistName) | ||
行 23: | 行 85: | ||
local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json' | local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json' | ||
-- local CALv2 = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json' | -- local CALv2 = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json' | ||
local artist = '' | local artist = '' | ||
local artist_list = CALv2[artistName] | local artist_list = CALv2[artistName] | ||
if artist_list then | if artist_list then | ||
if artist_list.__FullData__ then | if artist_list.__FullData__ then | ||
artist = fullCAL(artist_list.__FullData__) | |||
else | else | ||
artist = artistName | artist = defaultCAL(artistName, artist_list) | ||
end | end | ||
else | else | ||
artist = langLink(artistName) | |||
end | end | ||
return artist | return artist |
次編輯