Jump to content

Module:niv-utilities

From Wiktionary, the free dictionary


local export = {}

local gsub = mw.ustring.gsub
local rlower = mw.ustring.lower

local R = "\204\140" -- hacek

export.encode = {
	["ғ"] = "G", ["ӻ"] = "R", ["ӷ"] = "Q",
	["ӈ"] = "N", ["ӽ"] = "X", ["ч"] = "c",
	["р̌"] = "r", ["ӿ"] = "h", ["ӄ"] = "L",
	["ў"] = "w"
}

local function palatalise(text)
	text = rlower(text)
	text = gsub(text, "[яёюьи]", {
        ['я'] = 'jа', ['ё'] = 'jо',
        ['ю'] = 'ju', ['ь'] = 'j',
        ['и'] = "ji"
    })
	return text
end

function export.encipher(text)
	text = palatalise(text)
	text = gsub(text, ".", export.encode)
	text = gsub(text, "п[ʼ’]", "P")
	text = gsub(text, "т[ʼ’]", "T")
	text = gsub(text, "к[ʼ’]", "K")
	text = gsub(text, "L[ʼ’]", "q")
	if text:match("ʼ") then error("Uncoupled ’ found.") end
	return text
end

return export