Module:cel-bry-pro-sortkey

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

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

local remove_diacritics = u(0x0303) .. u(0x0307) .. u(0x0308) .. u(0x0323) -- tilde, dot above, diaeresis, dot below

local oneChar = {
	["β"] = "b" .. a, ["ð"] = "d" .. a, ["ɣ"] = "g" .. a, ["ɨ"] = "i", ["ʉ"] = "u", ["θ"] = "t" .. a
}

function export.makeSortKey(text, lang, sc)
	return mw.ustring.upper(mw.ustring.toNFC(mw.ustring.gsub(mw.ustring.toNFD(mw.ustring.gsub(mw.ustring.lower(text), ".", oneChar)), "[" .. remove_diacritics .. "]", ""))) -- decompose, remove appropriate diacritics, then recompose again
end

return export