「Module:ConvertLink」:修訂間差異

增加 831 位元組 、​ 2024年7月23日 (星期二)
修复无链接文本(vocal)日文显示
(CALv2更新完成)
(修复无链接文本(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 = {[' 旅人E']=''}
 
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 function formatJapaneseText(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 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
for _, data in ipairs(artist_list.__FullData__) do
artist = fullCAL(artist_list.__FullData__)
local display_ja = formatJapaneseText(data.display)
if data.link then
   artist = artist .. (display_ja and link('曲师列表#' .. data.link, display_ja) or '')
   else
   artist = artist .. (display_ja or '')
end
end
else
else
artist = artistName
artist = defaultCAL(artistName, artist_list)
for theLink, display in pairs(artist_list) do
if type(display)=='string' then
local display_ja = formatJapaneseText(display)
artist = string.gsub(artist, display, display_ja and link('曲师列表#' .. theLink, display_ja) or '')
elseif type(display)=='table' then
for _,d in pairs(display) do
local d_ja = formatJapaneseText(d)
artist = string.gsub(artist, d, d_ja and link('曲师列表#' .. theLink, d_ja) or '')
end
end
end
end
end
else
else
   artist = formatJapaneseText(artistName)
artist = langLink(artistName)
   artist = link('曲师列表#' .. artistName, artist)
end
end
return artist
return artist
956

次編輯