local export = {}
local u = mw.ustring.char
local a, b, c = u(0xF000), u(0xF001), u(0xF002)
-- Sort the old orthography (using the apostrophe) after the new orthography (using the acute accent).
local oneChar = {
["á"] = "a" .. a, ["ǵ"] = "g" .. a, ["x"] = "h" .. a, ["ı"] = "i", ["í"] = "i", ["q"] = "k" .. a, ["ń"] = "n" .. a, ["ó"] = "o" .. a, ["ú"] = "u" .. a, ["c"] = "z" .. b,
["ә"] = "а" .. a, ["ғ"] = "г" .. a, ["ё"] = "е" .. a, ["қ"] = "к" .. a, ["ң"] = "н" .. a, ["ө"] = "о" .. a, ["ү"] = "у" .. a, ["ў"] = "у" .. b, ["ҳ"] = "х" .. a
}
local twoChars = {
["aʼ"] = "a" .. b, ["gʼ"] = "g" .. b, ["nʼ"] = "n" .. b, ["oʼ"] = "o" .. b, ["uʼ"] = "u" .. b, ["sh"] = "z" .. a, ["ch"] = "z" .. c
}
function export.makeSortKey(text, lang, sc)
text = mw.ustring.gsub(mw.ustring.gsub(mw.ustring.lower(text), "iʼ", "ı" .. a), "i", "i" .. b) -- ensure "i" comes after "ı/iʼ"
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