Bước tới nội dung

Mô đun:uby-sortkey

Từ điển mở Wiktionary
local export = {}
local u = mw.ustring.char
local a, b, c, d, e, f, g, h, i, j, k, l, m, n, o = u(0xF000), u(0xF001), u(0xF002), u(0xF003), u(0xF004), u(0xF005), u(0xF006), u(0xF007), u(0xF008), u(0xF009), u(0xF00A), u(0xF00B), u(0xF00C), u(0xF00D), u(0xF00E)

local oneChar = {
	["ӷ"] = "г" .. c, ["ҕ"] = "г" .. d, ["ё"] = "е" .. a, ["ҙ"] = "з" .. b, ["ӡ"] = "з" .. d, ["қ"] = "к" .. c, ["ҟ"] = "к" .. f, ["ӄ"] = "к" .. k, ["ԯ"] = "л" .. a, ["ԥ"] = "п" .. b, ["ҧ"] = "п" .. c, ["ҫ"] = "с" .. b, ["ҭ"] = "т" .. b, ["ҳ"] = "х" .. e, ["ҵ"] = "ц" .. d, ["ҷ"] = "ч" .. a, ["ҽ"] = "ч" .. b, ["ҿ"] = "ч" .. c, ["ҩ"] = "ы" .. a, ["џ"] = "ы" .. b, ["ә"] = "ь" .. a
}

local twoChars = {
	["б'"] = "б" .. a, ["в'"] = "в" .. a, ["гь"] = "г" .. a, ["гә"] = "г" .. b, ["ӷь"] = "г" .. e, ["ҕь"] = "г" .. f, ["ӷә"] = "г" .. g, ["ҕә"] = "г" .. h, ["ӷ'"] = "г" .. i, ["ҕ'"] = "г" .. j, ["дә"] = "д" .. a, ["жь"] = "ж" .. a, ["жә"] = "ж" .. b, ["зә"] = "з" .. a, ["ҙә"] = "з" .. c, ["ӡь"] = "з" .. e, ["ӡә"] = "з" .. f, ["ӡ'"] = "з" .. g, ["кь"] = "к" .. a, ["кә"] = "к" .. b, ["қь"] = "к" .. d, ["қә"] = "к" .. e, ["ҟь"] = "к" .. g, ["ҟә"] = "к" .. h, ["ҟ'"] = "к" .. i, ["ӄь"] = "к" .. l, ["ӄә"] = "к" .. m, ["ӄ'"] = "к" .. n, ["ԯь"] = "л" .. b, ["м'"] = "м" .. a, ["п'"] = "п" .. a, ["ԥ'"] = "п" .. d, ["ҧ'"] = "п" .. e, ["сә"] = "с" .. a, ["ҫә"] = "с" .. c, ["тә"] = "т" .. a, ["ҭә"] = "т" .. c, ["ф'"] = "ф" .. a, ["хь"] = "х" .. a, ["хә"] = "х" .. b, ["х'"] = "х" .. c, ["ҳә"] = "х" .. f, ["ць"] = "ц" .. a, ["цә"] = "ц" .. b, ["ц'"] = "ц" .. c, ["ҵь"] = "ц" .. e, ["ҵә"] = "ц" .. f, ["ҵ'"] = "ц" .. g, ["шь"] = "ш" .. a, ["шә"] = "ш" .. b, ["џь"] = "ы" .. c
}

local threeChars = {
	["ӷ'ә"] = "г" .. k, ["ҕ'ә"] = "г" .. l, ["ҟ'ә"] = "к" .. j, ["ӄ'ә"] = "к" .. o, ["х'ә"] = "х" .. d
}

function export.makeSortKey(text, lang, sc)
	text = mw.ustring.lower(text)
	
	for from, to in pairs(threeChars) do
		text = mw.ustring.gsub(text, from, to)
	end
	
	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