Module:cel-pro-sortkey

From Linguifex
Revision as of 12:00, 21 April 2026 by Sware (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:cel-pro-sortkey/doc

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

local remove_diacritics = u(0x0304) -- macron

local oneChar = {
	["ɸ"] = "f", ["φ"] = "f", ["ʷ"] = "w"
}

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

return export