Jump to content

Module:RQ:pi:Sai Kam Mong

Long Wiktionary

Documentation for this module may be created at Module:RQ:pi:Sai Kam Mong/doc

local export = {};
local gsub = string.gsub  -- Can pretend it's all Latin-1!
local trim = mw.text.trim -- Except for trimmming strings.

function export.quote(frame)
	-- Convert from string if decimal, and trim if not.
	local pageno = tonumber(frame.args[1]) or trim(frame.args[1])
	if not pageno then
		return "Invalid or missing page number"
	end
	local quotid = frame.args[2]
	if quotid then
		quotid = trim(quotid)
		if string.len(quotid) == 0 then quotid = nil end
	end
	if not quotid then
		return "Passage ID is missing"
	end
	local wordid = tonumber(frame.args[3]) or 0
	local passages = frame.args["passages"] or 'RQ:pi:Sai Kam Mong/passages'
	passages = mw.loadData('Module:'..passages)
	passage = passages[pageno]
	if passage then
		passage=passage[quotid]
		if passage then
            local highlight = function() end
			local function consider_word(m1)
				if string.find(m1, "^{"..wordid.."%-") then
					return "'''"..m1.."'''"
				else
					return "{"..highlight(string.sub(m1, 2))
				end
			end
			highlight = function(m2)
				return gsub(m2, "%b{}", consider_word)
			end
			local text, tran, xlit
			text = highlight(passage[1])
			text = gsub(text, "{%d%d*-", "")
			text = gsub(text, "}", "")
			text = gsub(text, "''''''", "")
			tran = highlight(passage[2])
			tran = gsub(tran, "{%d%d*-", "")
			tran = gsub(tran, "}", "")
			tran = gsub(tran, "''''''", "")
			xlit = highlight(passage[3])
			xlit = gsub(xlit, "{%d%d*-", "")
			xlit = gsub(xlit, "}", "")
			xlit = gsub(xlit, "''''''", "")
			return frame:expandTemplate{title = trim(passages["reference"]),
				args = { pageno, text, tran, xlit,
					lang = passage.lang or passages[pageno].lang or passages.lang} }
		else
			return "No passage dubbed \"" .. quotid .. "\" on page " .. pageno
		end
	else
		return "There are no passages from page " .. pageno
	end
end
return export