Module:VO

local p = {} local KOrm = require('Module:Ko-rm') local lib = require('Module:Feature') local tabber = require('Module:Tabber')._main local ne = lib.isNotEmpty

local arguments = { language = true, language_s = true, language_t = true, character = true, name = true, name_s = true, name_t = true, fullname = true, fullname_s = true, fullname_t = true, korm = true }

local prefixes = { title = true, title_s = true, title_t = true, subtitle = true, subtitle2 = true, friendship = true, ascension = true, quest = true, hidden = true, other = true, tx = true, tx_s = true, tx_t = true, rm = true, rm_s = true, rm_t = true, tl = true, tl_s = true, tl_t = true, actualtx = true, actualtx_s = true, actualtx_t = true, actualrm = true, actualrm_s = true, actualrm_t = true, actualtl = true, actualtl_s = true, actualtl_t = true, mention = true }

local lib = require('Module:Feature') local namespace = require('Module:Namespace detect')._main

-- entry function obtain arguments function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {       parentFirst = true,        removeBlanks = false,        wrappers = {'Template:VO'}    }) return p._main(args, frame) end

-- main function function p._main(args, frame) local voicelines = {} local settings = {} settings.korm = (ne(args.korm) and args.korm) or '1' settings.languagePrefix = p._getLanguagePrefix(args.language) or '' settings.languageCode = p._getLanguageCode(args.language) or 'en' if args.language_s then settings.languageCode_s = p._getLanguageCode(args.language_s) end if args.language_t then settings.languageCode_t = p._getLanguageCode(args.language_t) end settings.character = args.character or mw.title.getCurrentTitle.rootText settings.name = args.name or settings.character if args.name_s then settings.name_s = args.name_s end if args.name_t then settings.name_t = args.name_t end settings.fullname = args.fullname or settings.name -- store values into voicelines p._parseArguments(args, voicelines, settings) -- create table local result = '' if settings.languageCode_s == 'zh' and settings.languageCode_t == 'zh-Hant' then result = tabber{ 'Simplified', p._createTable(voicelines, settings, '_s'), 'Traditional', {   			'Note: The following transcriptions and romanizations may differ slightly from the audio as the Chinese Voice-Overs are based on the Simplified Chinese text.\n', p._createTable(voicelines, settings, '_t') }   	}	else result = p._createTable(voicelines, settings, '') end return result end

function p._getLanguagePrefix(value) if (value == 'en' or value == '') then return '' elseif (value == 'zh' or value == 'cn' or value == 'zh-tw') then return 'ZH_' elseif (value == 'ja' or value == 'jp') then return 'JA_' elseif (value == 'ko' or value == 'kr' or value == 'kr_hj') then return 'KO_' end end

function p._getLanguageCode(value) if (value == 'en' or value == '') then return 'en' elseif (value == 'zh' or value == 'cn') then return 'zh' elseif (value == 'zh-tw') then return 'zh-Hant' elseif (value == 'ja' or value == 'jp') then return 'ja' elseif (value == 'ko' or value == 'kr' or value == 'kr_hj') then return 'ko' end end

-- clean title for id function p._cleanTitle(title) return title:gsub('%[%[.*%|', ):gsub('%[%[', ):gsub('%]%]', ''):gsub('<', '&lt;'):gsub('>', '&gt;'):gsub('"', '&quot;') end

function p._parseArguments(args, voicelines, settings) for key, value in pairs(args) do       if (arguments[key] == nil) then local prefix, index, suffix = string.match(key, '^vo_([0-9][0-9])_([0-9][0-9])_(.*)$') prefix = tonumber(prefix) index = tonumber(index) if prefix == nil then error('The parameter ' .. key .. ' = ' .. value .. ' has an invalid prefix name') end if index == nil then error('The parameter ' .. key .. ' = ' .. value .. ' has an invalid index name') end voicelines[prefix] = voicelines[prefix] or {} voicelines[prefix][index] = voicelines[prefix][index] or {} -- replace the {language}, {character}, {name}, and {fullname} with variables value = value:gsub('%{character%}', settings.character) value = value:gsub('%{language%}', settings.languagePrefix) value = value:gsub('%{language_s%}', settings.languagePrefix_s or settings.languagePrefix) value = value:gsub('%{language_t%}', settings.languagePrefix_t or settings.languagePrefix) value = value:gsub('%{name%}', settings.name) value = value:gsub('%{name_s%}', settings.name_s or settings.name) value = value:gsub('%{name_t%}', settings.name_t or settings.name) value = value:gsub('%{fullname%}', settings.fullname) value = value:gsub('%{fullname_s}', settings.fullname_s or settings.fullname) value = value:gsub('%{fullname_t}', settings.fullname_t or settings.fullname) -- store the value if (suffix == 'file') then voicelines[prefix][index]['file'] = ' [[Media:' .. value .. ']]   ' elseif (prefixes[suffix]) then voicelines[prefix][index][suffix] = value else error('The parameter ' .. key .. ' = ' .. value .. ' has an invalid suffix name') end end end end

function p._createTable(voicelines, settings, suffix) if suffix == nil then suffix = '' end local lang = settings['languageCode' .. suffix] or settings.languageCode local categories = mw.html.create local wikitable = mw.html.create('table'):addClass('wikitable'):css('width', '100%'):css('box-sizing', 'border-box'):newline -- create table header row local tr = wikitable:tag('tr'):addClass('hidden') tr:tag('th'):css('width', '30%'):wikitext('Title and Requirements') tr:tag('th'):css('width', '70%'):wikitext('Details') tr:done:newline -- create table rows for prefix=1,99 do		local groupedTitles = false if voicelines[prefix] ~= nil then if voicelines[prefix][0] ~= nil then groupedTitles = true end end for index, values in ipairs(voicelines[prefix] or {}) do           local tr = wikitable:tag('tr') -- section groups or separate if (groupedTitles and index == 1) then local th = mw.html.create th:tag('span'):attr('lang',lang):wikitext((voicelines[prefix][0]['title' .. suffix] or voicelines[prefix][0]['title'] or Unknown)) -- add subtitle if exists if voicelines[prefix][0]['subtitle'] then th:tag('div'):attr('id',p._cleanTitle(voicelines[prefix][0]['subtitle'])):tag('small'):wikitext('(',voicelines[prefix][0]['subtitle'],')') end -- add subtitle2 if exists if voicelines[prefix][0]['subtitle2'] then th:tag('div'):tag('small'):wikitext('[', voicelines[prefix][0]['subtitle2'],']') end tr:tag('th'):addClass('mobile-only'):node(th) tr = wikitable:tag('tr') tr:tag('th'):addClass('hidden'):attr('rowspan', #voicelines[prefix]):attr('id', p._cleanTitle(voicelines[prefix][0]['title' .. suffix] or voicelines[prefix][0]['title'] or Unknown)):node(th) elseif (not groupedTitles) then local th = mw.html.create th:tag('span'):attr('lang',lang):wikitext((values['title' .. suffix] or values['title'] or Unknown)) -- add subtitle if exists if values['subtitle'] then th:tag('div'):attr('id',p._cleanTitle(values['subtitle'])):tag('small'):wikitext('(',values['subtitle'],')') end -- add subtitle2 if exists if values['subtitle2'] then th:tag('div'):tag('small'):wikitext('[',values['subtitle2'],']') end -- add requirements divider if values['friendship'] or values['ascension'] or values['quest'] or values['other'] then th:tag('hr'):addClass('theme-border-color'):css('border-width','0.5px'):css('border-style','dashed') end -- add friendship if exists if values['friendship'] then th:tag('div'):tag('small'):wikitext(' '):tag('i'):wikitext('Friendship Lv. ', values['friendship']) end -- add ascension if exists if values['ascension'] then th:tag('div'):tag('small'):wikitext(' '):tag('i'):wikitext('Ascension Phase ', values['ascension']) end -- add quest if exists if values['quest'] then th:tag('div'):tag('small'):wikitext(' '):tag('i'):wikitext(lib.ternary(values['quest'] == '???', '???',  .. values['quest'] .. )) end -- add removal quest if exists if values['hidden'] then th:tag('div'):tag('small'):wikitext(' Not Available after '):tag('i'):wikitext(, values['hidden'], ) end -- add other if exists if values['other'] then th:tag('div'):tag('small'):tag('i'):wikitext('(', values['other'], ')') end tr:tag('th'):addClass('mobile-only'):node(th) tr = wikitable:tag('tr') tr:tag('th'):addClass('hidden'):attr('id', p._cleanTitle(values['title' .. suffix] or values['title'] or Unknown)):node(th) end local td = tr:tag('td') if values['file'] then td:wikitext(values['file']) td:wikitext(' ') end --store values local TX = values['transcript' .. suffix] or values['tx' .. suffix] or values['transcript'] or values['tx'] local RM = values['romanized' .. suffix] or values['rm' .. suffix] or values['romanized'] or values['rm'] local TL = values['translation' .. suffix] or values['tl' .. suffix] or values['translation'] or values['tl'] local actTX = values['actualtx' .. suffix] or values['actualtx'] local actRM = values['actualrm' .. suffix] or values['actualrm'] local actTL = values['actualtl' .. suffix] or values['actualtl'] if TX == 'N/A' then if settings.languageCode == 'en' then if (groupedTitles and index == 1) then td:tag('b'):wikitext(settings.character, ' does not feature any ', voicelines[prefix][0]['title'], ' Voice-Over') else td:tag('b'):wikitext(settings.character, ' does not feature any ', values['title'], ' Voice-Over') end else if (groupedTitles and index == 1) then td:tag('b'):wikitext(settings.character, ' does not feature any ', (voicelines[prefix][0]['subtitle' .. suffix] or voicelines[prefix][0]['subtitle']), ' Voice-Over') else td:tag('b'):wikitext(settings.character, ' does not feature any ', (values['subtitle' .. suffix] or values['subtitle']), ' Voice-Over') end end elseif TX == 'N/P' then td:tag('i'):wikitext('(Not recorded in Profile)') elseif (TX ~= 'N/P' and TX ~= 'N/A' and ne(TX)) then td:tag('span'):attr('lang',lang):wikitext(KOrm.strip(TX)) end if (lang == 'ko' and settings.korm ~= '0' and ne(TX)) then local koRM = KOrm._main{(TX:gsub('%[%[Media:.- ', '')), sent = 1} if (settings.korm == '1' and ne(RM)) then td:tag('div'):tag('small'):tag('i'):wikitext(RM) elseif settings.korm == '1' then td:tag('div'):tag('small'):tag('i'):wikitext(koRM) categories:wikitext('') elseif (settings.korm == '2') then if ne(RM) then td:tag('div'):tag('small'):wikitext('Manual-RM: ['):tag('i'):wikitext(RM):done:wikitext(']') end td:tag('div'):tag('small'):wikitext('Auto-RM: ['):tag('i'):wikitext(koRM):done:wikitext(']') end elseif ne(RM) then td:tag('div'):tag('small'):tag('i'):wikitext(RM) end if ne(TL) then td:tag('div'):tag('small'):wikitext('(', TL, ')') end if ne(actTX) then local divsmall = td:tag('div'):tag('small') divsmall:wikitext('(Actual Voice-Over: '):tag('span'):attr('lang',lang):wikitext(actTX):done:wikitext(')') if ne(actRM) then divsmall:wikitext(' Actual Romanization: '):tag('i'):wikitext(actRM) end if ne(actTL) then divsmall:wikitext(' Actual Translation: ', actTL) end end if ne(values['mention']) then local mention = lib.split(values['mention'], ',') for key, value in pairs(mention) do           		categories:wikitext('') end end td:done tr:done:newline end end wikitable:node(namespace({main=categories})) return wikitable end

return p