Module:syc-utilities/sandbox

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


local export = {}
local lang = require("Module:languages").getByCode("syc")
local m_utilities = require("Module:utilities")
local m_links = require("Module:links")
local m_headword = require("Module:headword")
local rsplit = mw.text.split

local function link(term, alt, id)
	if word == "" or word == "—" then
		return word
	else
		return m_links.full_link({
			term = term,
			alt = alt,
			lang = lang,
			id = id,
		}, face)
	end
end

local function validateRoot(rootTable, joined_root)
	if type(rootTable) ~= "table" then
		error("rootTable is not a table", 2)
	end

	for i, letter in ipairs(rootTable) do
		if mw.ustring.len(letter) > 1 then
            error("'" .. letter .. "', the " .. ordinal[i] ..
                      " letter in the root '" .. joined_root ..
                      "' should be a single letter.")
        end
	end
end

function export.root(frame)
	local output = {}
	local categories = {}
	local title = mw.title.getCurrentTitle()
	local fulltitle = title.fullText
	local namespace = title.nsText

	local params = {
		[1] = {},
		["nocat"] = { type = "boolean" },
		["plain"] = { type = "boolean" },
		["notext"] = { type = "boolean" },
		["sense"] = {},
	}

	local args = require("Module:parameters").process(frame:getParent().args,
			params)

	-- split string, iterate through string to remove all non-Geez characters and convert each Geez character to sixth series
	if not args[1] and namespace == "Template" then
		args[1] = "ܟ-ܬ-ܒ"
	end
	
	local link_text
	link_text = link(args[1])
	table.insert(output, link_text)
	table.insert(categories, m_utilities.format_categories(
		{"Classical Syriac terms belonging to the root " .. args[1]}, syc))
		if args["nocat"] or args["plain"] then
			return table.concat(output)
		else
			local term_count = mw.site.stats.pagesInCategory("Classical Syriac terms belonging to the root " .. args[1], "pages")
			return "<table class=\"wikitable\" style=\"float: right; clear: right; text-align: center;\"><tr><th>Syriac root</th></tr><tr><td>" .. link_text .. "</td></tr><tr><td>[[:Category:" .. lang:getCanonicalName() .. " terms belonging to the root " .. args[1] .. "|" .. term_count .. " term" .. (term_count == 1 and "" or "s") .. "]]</td></tr></table>" .. table.concat(categories)
		end
end

return export