Module:Script

local p = {}

local utilsArg = require("Module:UtilsArg") local utilsMarkup = require("Module:UtilsMarkup") local utilsTable = require("Module:UtilsTable")

local data = require("Module:Script/Data")

function p.Main(frame) local frameArgs = utilsTable.clone(frame:getParent.args) if frameArgs[2] then frameArgs[2] = string.upper(frame:preprocess(frameArgs[2])) end local args, err = utilsArg.parse(frameArgs, p.Templates.Script) local errCategories = err and utilsMarkup.categories(err.categories) or "" return p.transliterate(args) .. errCategories end

function p.transliterate(args) local scriptId = args.scriptId local chars = args.text local size = args.size local script = data[scriptId or ""] if not script then return "" end local fileFormat = script.fileFormat local defaultSize = script.defaultSize and "x"..script.defaultSize.."px" or nil local charset = utilsTable.invert(script.charset) local html = mw.html.create("span"):css({ ["display"] = "inline-block" }) for _, char in ipairs(chars or {}) do		if charset[char] then local filename = string.format(fileFormat, char, char) local file = utilsMarkup.file(filename, {				size = size or defaultSize,				caption = char,			}) local span = mw.html.create("span") :attr({					class = "tooltip",					title = char,				}) :wikitext(file) html:node(span) else local span = mw.html.create("span"):wikitext(char) html:node(span) end end return tostring(html) end

p.Schemas = { Data = { type = "map", required = true, desc = "Key value pairs defining in-game scripts, where the key corresponds to the  parameter of Template:Script.", keys = { type = "string", },		values = { type = "record", properties = { {					name = "fileFormat", type = "string", required = true, desc = "The file format for the script characters.", },				{					name = "defaultSize", type = "number", desc = "If unspecified, the default size will be the size of the character's file.", },				{					name = "charset", type = "array", required = true, items = { type = "string" }, desc = "An array of all the source characters defined for the script.", },			},		},	}, }

p.Templates = { Script = { wip = true, purpose = "Transliterates in-game scripts from their source language (Japanese or English).", format = "inline", params = { [1] = {				name = "scriptId", type = "string", required = true, enum = utilsTable.merge({}, utilsTable.keys(data), { 					reference = "Module:Script/Data" 				}), desc = " Identifier for the language script. The various forms of Hylian are named after the first game in which they were released. ", },			[2] = {				name = "text", type = "string", required = true, enumDependsOn = "scriptId", enum = function(scriptId) local chars = utilsTable.concat(data[scriptId] and data[scriptId].charset or {}, " ", "　", "", "\n", "\t") return utilsTable.merge({}, chars, {						reference = "Module:Script/Data" 					}) end, split = "", desc = " The text to transliterate into an in-game language. Only characters which are defined for the script are allowed, as well as the whitespace, which is ignored. Newlines are respected, however. ", },			size = { type = "string", canOmit = true, desc = "Size of the characters in px. Defaults to the script's  if defined at Module:Script/Data. Otherwise, defaults to the size of the character images.", },		},		examples = { {"Gerudo", "The quick brown fox jumps over the lazy dog"}, {"Hylian OoT", [[ タチツテトナニヌネニノハヒフヘホ

ヘホタチツテトナニヌネノハヒフ ]]},			{"Hylian TWW", "ァィゥェォッャュョ　. 、「」！？１２３４５６７８９０"}, {"Hylian TP", "The quick brown fox jumps over the lazy dog"}, {"Hylian SS", "The quick brown fox jumps over the lazy dog"}, {"Hylian ALBW", "The quick brown fox jumps over the lazy dog"}, {"Lorulean", "The quick brown fox jumps over the lazy dog"}, {				desc = "Non-default sizes", args = {"Hylian ALBW", size = "x50px", "Big Font"}, },			{				desc = "Invalid characters are ignored and simply passed on as-is.", args = {"Hylian TWW", "This won't work because TWW Hylian is based on katakana."}, },			{				args = {"Hylian ALBW", "formatting won't work either"}, },			{				desc = " is required", args = {}, },			{				args = {""}, },			{				args = {"invalid ID", "foo"}, },			{				desc = " can be empty, but it cannot be undefined.", args = {"Hylian ALBW", ""}, },			{				args = {"Hylian ALBW"}, },		},	}, }

return p