Honkai Impact 3 Wiki

Hello, Captain! Since mid Dec of 2022, discussion tab and comments under article pages are enabled. Log in and share your thoughts with us! Our Discord Server is also waiting for you~

READ MORE

Honkai Impact 3 Wiki
Advertisement

Requires Module:Lang/code (list of ISO 639-1 Language Codes)


local p = {}
local param = {}
local langCode = require('Module:Lang/code')

function trim(s)
	return s:match "^%s*(.-)%s*$"
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		parentFirst = true,
		wrappers = {
			'Template:Lang'
		}
	})
	return p._main(args)
end

function eachLang(altLangs, args, tBlock, key, value)
	local part = mw.html.create('span')
	local append = {}
	if langCode[key] then
		if not(args.mini) then
			part:wikitext("<u>" .. langCode[key] .. "</u>" .. ": ")
		end
		part:tag("span")
			:attr("lang", key)
			:wikitext(value)
		if tBlock[key .. "_rm"] then -- Romanization
			table.insert(append, "<i>" .. args[key .. "_rm"] .. "</i>")
		end
		if tBlock[key .. "_tn"] then -- Translation
			table.insert(append, "\"" .. args[key .. "_tn"] .. "\"")
		end
		if tBlock[key .. "_lit"] then -- Literal
			table.insert(append, "lit. \"" .. args[key .. "_lit"] .. "\"")
		end
		if #append>0 then
			part:wikitext(" " .. table.concat(append, ", "))
		end
	else
		part:wikitext(key .. ": " .. value)
	end
	table.insert(altLangs, tostring(part))
end

function p._main(args)
	local out = mw.html.create('')

	local tBlock = {sort = true, mini = true}

	--Obtain all _tn keys
	for k, v in pairs(args) do
		if mw.ustring.find(k, "_rm$")
			or mw.ustring.find(k, "_tn$")
			or mw.ustring.find(k, "_lit$") then
			tBlock[k] = true
		end
	end
	--Obtain all numerical keys
	for k,v in ipairs(args) do
		tBlock[k] = true
	end

	--Output default Value
	out:wikitext(args[1])

	local altLangs = {}
	--Process Sort Paremeter (Split by Delimiter: comma)
	for sKey in string.gmatch(args.sort or "", "([^,]+)") do
		if not(tBlock[sKey]) and args[sKey] then
			eachLang(altLangs, args, tBlock, sKey, args[sKey])
			tBlock[sKey]=true
		end
	end

	--Process Rest
	for key, value in pairs(args) do
		if not(tBlock[key]) then
			eachLang(altLangs, args, tBlock, key, value)
		end
	end
	if #altLangs>0 then
		if not(args.mini) then
			out:wikitext(' (')
		end
		out:wikitext(table.concat(altLangs,'; '))
		if not(args.mini) then
			out:wikitext(')')
		end
	end
	return tostring(out)
end

return p
Advertisement