Module:ulc-sortkey

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

local export = {}
local u = mw.ustring.char
local a, b = u(0xF000), u(0xF001)

local oneChar = {
	["ё"] = "е" .. a, ["ӈ"] = "н" .. b
}

local twoChars = {
	["дʼ"] = "д" .. a, ["нʼ"] = "н" .. a
}

function export.makeSortKey(text, lang, sc)
	text = mw.ustring.lower(text)
	
	for from, to in pairs(twoChars) do
		text = mw.ustring.gsub(text, from, to)
	end
	
	return mw.ustring.upper(mw.ustring.gsub(text, ".", oneChar))
end

return export