local export = {}
local us = mw.ustring
local prefix = ""
local suffix = us.char(0x3130)
function G(s)
return prefix .. s .. suffix
end
local initial_consonants = {
= G("ㄱ"),
= G("ㄱㄱ"),
= G("ㄴ"),
= G("ㄴㄴ"),
= G("ㄷ"),
= G("ㄷㄷ"),
= G("ㄹ"),
= G("ㅁ"),
= G("ㅂ"),
= G("ㅂㄱ"),
= G("ㅂㄷ"),
= G("ㅂㅂ"),
= G("ㅂㅅ"),
= G("ㅂㅅㄱ"),
= G("ㅂㅅㄷ"),
= G("ㅂㅅㅈ"),
= G("ㅂㅈ"),
= G("ㅂㅌ"),
= G("ㅂㅎ"), -- hack
= G("ㅅ"),
= G("ㅅㄱ"),
= G("ㅅㄴ"),
= G("ㅅㄷ"),
= G("ㅅㅁ"),
= G("ㅅㅂ"),
= G("ㅅㅂㄱ"),
= G("ㅅㅅ"),
= G("ㅅㅋ"),
= G("ㅅㅌ"),
= G("ㅅㅍ"),
= G("ㅅㅎ"), -- hack
= G("ㅇ"),
= G("ㅇㅇ"),
= G("ㅇㅎ"), -- hack
= G("ㅈ"),
= G("ㅈㅈ"),
= G("ㅊ"),
= G("ㅋ"),
= G("ㅌ"),
= G("ㅍ"),
= G("ㅎ"),
= G("ㅎㅎ"),
= G("ㆆ"),
}
local medials = {
= G("ㅏ"),
= G("ㅐ"),
= G("ㅑ"),
= G("ㅒ"),
= G("ㅓ"),
= G("ㅔ"),
= G("ㅕ"),
= G("ㅖ"),
= G("ㅗ"),
= G("ㅗㅏ"),
= G("ㅗㅐ"),
= G("ㅗㅣ"),
= G("ㅛ"),
= G("ㅛㅑ"),
= G("ㅛㅒ"),
= G("ㅛㅣ"),
= G("ㅜ"),
= G("ㅜㅓ"),
= G("ㅜㅔ"),
= G("ㅜㅣ"),
= G("ㅠ"),
= G("ㅠㅕ"),
= G("ㅠㅖ"),
= G("ㅠㅣ"),
= G("ㅡ"),
= G("ㅡㅣ"),
= G("ㅣ"),
= G("ㆍ"),
= G("ㆍㅣ"),
}
prefix = us.char(0x318F)
local final_consonants = {
= G("ㄱ"),
= G("ㄱㄱ"),
= G("ㄱㅅ"),
= G("ㄴ"),
= G("ㄴㄷ"),
= G("ㄴㅅ"),
= G("ㄴㅅㅎ"), -- hack
= G("ㄴㅈ"),
= G("ㄴㅌ"),
= G("ㄴㅎ"),
= G("ㄷ"),
= G("ㄹ"),
= G("ㄹㄱ"),
= G("ㄹㄱㅅ"),
= G("ㄹㅁ"),
= G("ㄹㅂ"),
= G("ㄹㅅ"),
= G("ㄹㅅㅎ"), -- hack
= G("ㄹㅌ"),
= G("ㄹㅍ"),
= G("ㄹㅎ"),
= G("ㄹㆆ"),
= G("ㅁ"),
= G("ㅁㄱ"),
= G("ㅁㅂ"),
= G("ㅁㅅ"),
= G("ㅁㅅㅎ"),
= G("ㅁㅊ"),
= G("ㅂ"),
= G("ㅂㄹ"),
= G("ㅂㅅ"),
= G("ㅅ"),
= G("ㅅㄱ"),
= G("ㅅㄷ"),
= G("ㅅㅅ"),
= G("ㅅㅎ"), -- hack
= G("ㅇ"),
= G("ㅇㅎ"), -- hack
= G("ㅇㅎㅅ"), -- hack
= G("ㅈ"),
= G("ㅊ"),
= G("ㅋ"),
= G("ㅌ"),
= G("ㅍ"),
= G("ㅎ"),
}
function export.makeSortKey(text, lang, sc)
text = us.toNFD(text)
text, _ = us.gsub(text, '.', initial_consonants)
text, _ = us.gsub(text, '.', medials)
text, _ = us.gsub(text, '.', final_consonants)
return text
end
return export