Module:tab-sortkey

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

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

local oneChar = {
	["ё"] = "е" .. a
}

local twoChars = {
	["аь"] = "а" .. a, ["гг"] = "г" .. a, ["гъ"] = "г" .. b, ["гь"] = "г" .. c, ["жв"] = "ж" .. a, ["кк"] = "к" .. a, ["къ"] = "к" .. b, ["кь"] = "к" .. c, ["кӏ"] = "к" .. d, ["пп"] = "п" .. a, ["пӏ"] = "п" .. b, ["тт"] = "т" .. a, ["тӏ"] = "т" .. b, ["уь"] = "у" .. a, ["хъ"] = "х" .. a, ["хь"] = "х" .. b, ["цц"] = "ц" .. a, ["цӏ"] = "ц" .. b, ["чв"] = "ч" .. a, ["чч"] = "ч" .. b, ["чӏ"] = "ч" .. c, ["шв"] = "ш" .. 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