Module:gem-pro-sortkey

Revision as of 09:20, 27 April 2024 by wikt>SurjectionBot (Protected "Module:gem-pro-sortkey": (bot) automatically protect highly visible templates/modules (reference score: 1994+ >= 1000) ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local export = {}
local u = mw.ustring.char

local remove_diacritics = u(0x0302) .. u(0x0304) -- circumflex, macron

local oneChar = {
	["ą"] = "an", ["į"] = "in", ["ǫ"] = "on", ["ų"] = "un"
}

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