Jump to content

Module:mai-utilities

From Wiktionary, the free dictionary


local export = {}

local m_links = require("Module:links")
local m_translit = require("Module:mai-IPA2")
local m_pron = require("Module:mai-IPA")

function export.usex(frame)
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().text
	local text = {}
	local example = args[1] or error("Example has not been specified. Please pass parameter 1 to the module invocation.")
	local translation = args[2] or ""

	if (not mw.ustring.match(example, "'''")) and mw.ustring.match(example, pagename) then
		example = mw.ustring.gsub(example, pagename, "'''" .. pagename .. "'''")
	end	
	local translit = m_translit.tr(m_links.remove_links(example), "mai", "Deva")
	example = mw.ustring.gsub(example, "[<ᵊ>•ॱ‌‍]", "")

	table.insert(text, ('<span lang="mai" class="Deva">%s</span>'):format(example))
	if mw.ustring.match(example, "[\.\?!।]") then
		table.insert(text, "<dl><dd>''" .. translit .. "''</dd><dd>" .. translation .. "</dd></dl>")
	else
		table.insert(text, "&nbsp; ―&nbsp; ''" .. translit .. "''&nbsp; ―&nbsp; " .. translation)
	end
	return table.concat(text)
end

function export.link(frame)
	if type(frame) == "table" then
		args = frame:getParent().args
		text = args[1]
		def = args[2] or false
		vert = args["v"] or false
	else
		text = frame
	end
	text = ('<span lang="mai" class="Deva">[[%s#Maithili|'):format(mw.ustring.gsub(text, "[<ᵊ>ॱ•‌‍]", "")) .. 
		('%s]]</span>'):format(mw.ustring.gsub(text, "[<ᵊ>•ॱ‌]", "")) ..
		(vert and "<div style=\"line-height:1pt; font-size:90%; color:#888\"><br>" or " [") .. m_translit.tr(text, "mai", "Deva") .. 
		(def and ', “' .. def .. '”' or "") .. (vert and "</div>" or "]")
	return text
end

return export