Module:User:Catonif/RQ:xum:TI

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Catonif, for their own experimentation. Items in this module may be added and removed at Catonif's discretion; do not rely on this module's stability.


local p = {};

local year = {};
year["1"] = "early 2<sup>nd</sup>";

local lines = {}; local text = {}; local tr = {}; local t = {};

local roman = {};
	roman["1"] = "I";
	roman["2"] = "II";
	roman["3"] = "III";
	roman["4"] = "IV";
	roman["5"] = "V";
	roman["6"] = "VI";
	roman["7"] = "VII";

local reg = "<([^:<>]+):([^:<>]+)>";
local reg_simple = "<([^:<>]+)>";

local function wrapInCollapsible(always, off, on)

	return
'<div class="vsSwitcher" data-toggle-category="inscriptions" style="width:fit-content">'
.. always
.. '<span class="vsHide">'
.. off
.. '</span><span class="vsToggleElement" style="margin-left: 1em;"></span>'
.. '<div class="vsHide" style="display:block">\n'
.. on
.. '</div></div>';

end

local function formatText(here_text, isLemma, bold, indent)

	local final_bold;

	if (isLemma) then
		here_text, _ = here_text:gsub(reg, function (str, id)
			id = id:gsub("%-.+", ""); local str_display = str:gsub("%[.+%]", ""); str = str:gsub("[%[%]]", "")
			if (id == bold) then return "'''[[" .. str .. "#Umbrian|" .. str_display .. "]]'''";
			else return "[[" .. id .. "#Umbrian|" .. str_display .. "]]"; end
		end);
	else
		here_text, _ = here_text:gsub(reg, function (str, id)
			local str_display = str:gsub("%[.+%]", ""); str = str:gsub("[%[%]]", "")
			if (str == bold) then final_bold = id; return "'''" .. str_display .. "'''";
			else return str_display; end
		end)
	end

	here_text = here_text:gsub("{", "<span class=\"Ital\" lang=\"xum\">"):gsub("}", "</span>")
		:gsub("([0-9]+a?)", "<sup>%1</sup>"):gsub("%.", "[...]")

	return indent .. here_text .. "\n", final_bold;

end

local function format(here_tr, bold, it, isLemma, indent)

	local function boldify (str, id)
		if (id == bold) then return "'''" .. str .. "'''";
		elseif (isLemma) then
			if (id:gsub("%-.+", "") == bold) then return "'''" .. str .. "'''";
			else return str; end
		else return str; end
	end

	local r, _ = here_tr:gsub(reg, boldify):gsub(reg_simple, function (x) return boldify(x, x) end)

	if (it) then return indent .. ":''" .. r .. "''\n";
	else return indent .. ":" .. r .. "\n"; end

end

local function getEntry(table, quote, precise, isLemma, bold, trad, indent)

	local r = "";
	local r_;

	local here_text, here_tr;

	if (precise == nil) then here_text = text[quote]; here_tr = tr[quote];
	else here_text = text[quote .. "/" .. precise]; here_tr = tr[quote .. "/" .. precise] end

	if (here_text:match(",")) then
		for v in string.gmatch(here_text, "([^,]+)") do
			r_, _ = getEntry(table, quote, v, isLemma, bold, false, indent);
			r = r .. r_;
		end
	else
		r_, bold = formatText(here_text, isLemma, bold, indent);
		r = r .. r_;
		if (here_tr ~= nil) then r = r .. format(here_tr, bold, true, isLemma, indent); end
	end

	if (trad) then r = r .. format(t[quote], bold, false, isLemma, indent);
	else
		local here_t = t[quote .. "/" .. precise];
		if (here_t ~= nil) then r = r .. format(here_t, bold, false, isLemma, indent); end
	end

	return r, bold;

end

function p.quote(frame)

	local number = frame.args["number"];
	local face = frame.args["face"];

	local table = number .. face;

	local list = require("Module:User:Catonif/RQ:xum:TI/" .. table);

	lines = list["lines"];
	text = list["text"];
	tr = list["tr"];
	t = list["t"];

	local here_year = year[number];

	local quote = frame.args["quote"];

	local precise = frame.args["precise"]; if (precise == "") then precise = nil; end


	local here_lines;
	if (precise == nil) then
		here_lines = lines[quote];
	else
		here_lines = lines[quote .. "/" .. precise];
		if (here_lines == nil) then
			here_lines = "line " .. precise;
		end
	end

	local always = "'''" .. here_year .. " century <small class='ce-date'>[[Appendix:Glossary#BCE|<span title=\"Glossary and display preference\">BCE</span>]]</small>''', ''[[w:Iguvine Tablets|Iguvine Tablets]]'', table " .. roman[number] .. ", face " .. face:upper() .. " ([https://web.archive.org/web/20221005184445im_/http://www.tavoleeugubine.it/public/image/tavoleeugubine/foto%20" .. roman[number] .. face .. ".jpg photo]; [https://web.archive.org/web/20221005184445if_/http://www.tavoleeugubine.it/public/image/tavoleeugubine/facsimileTI-" .. table .. ".jpg facsimile]), " .. here_lines;

	local show = ":\n";

	local bold = frame.args["bold"];
	local isLemma = frame.args["lemma"] == "1";

	local indent = ":";

	local hide = getEntry(table, quote, precise, isLemma, bold, true, indent);

	local r = wrapInCollapsible(always, show, hide);

	return r;

end

return p;