This module will sort Vietnamese language text. It is also used to sort Muong and Nguôn.
The module should preferably not be called directly from templates or other modules.
To use it from a template, use {{sortkey}}
.
Within a module, use Module:languages#Language:makeSortKey.
For testcases, see Module:vi-sortkey/testcases.
makeSortKey(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.Alphabetic order: a ă â b c d đ e ê g h i k l m n o ô ơ p q r s t u ư v x y.
Order of tonal diacritics: currently a, à, ả, ã, á, ạ; alternative, a, á, à, ả, ã, ạ.
See the discussion in the Beer Parlour.
TUYE₂N¹ NGO₂N¹ TOAN² THE₂⁵ GIO₃I⁵ VE₂² NHA₃N¹ QUYE₂N² CUA³ LIE₂N¹ HO₃P⁶ QUO₂C⁵
CO₂NG¹ BA₂NG²
D₂AI⁶
AC-SI-ME⁵T⁵
TA₃M¹ LY⁵
NGHE₂²
)NGHE₂⁶
)NGON¹
)NGON⁵
)NGON⁶
)NGOY¹
)NGO₂I¹
)NGO₂N¹
)NGO₂N¹
)A¹
)A²
)A³
)A⁴
)A⁵
)A⁶
)AC¹
)AC²
)AC³
)AC⁴
)AC⁵
)AC⁶
)AN¹
)AN²
)AN³
)AN⁴
)AN⁵
)AN⁶
)A₂¹
)A₂²
)A₂³
)A₂⁴
)A₂⁵
)A₂⁶
)A₂C¹
)A₂C²
)A₂C³
)A₂C⁴
)A₂C⁵
)A₂C⁶
)A₂N¹
)A₂N²
)A₂N³
)A₂N⁴
)A₂N⁵
)A₂N⁶
)A₃¹
)A₃²
)A₃³
)A₃⁴
)A₃⁵
)A₃⁶
)A₃C¹
)A₃C²
)A₃C³
)A₃C⁴
)A₃C⁵
)A₃C⁶
)A₃N¹
)A₃N²
)A₃N³
)A₃N⁴
)A₃N⁵
)A₃N⁶
)B¹
)BC¹
)BN¹
)C¹
)CC¹
)CN¹
)D¹
)DC¹
)DN¹
)D₂¹
)D₂C¹
)D₂N¹
)E¹
)E²
)E³
)E⁴
)E⁵
)E⁶
)EC¹
)EC²
)EC³
)EC⁴
)EC⁵
)EC⁶
)EN¹
)EN²
)EN³
)EN⁴
)EN⁵
)EN⁶
)E₂¹
)E₂²
)E₂³
)E₂⁴
)E₂⁵
)E₂⁶
)E₂C¹
)E₂C²
)E₂C³
)E₂C⁴
)E₂C⁵
)E₂C⁶
)E₂N¹
)E₂N²
)E₂N³
)E₂N⁴
)E₂N⁵
)E₂N⁶
)G¹
)GC¹
)GN¹
)H¹
)HC¹
)HN¹
)I¹
)I²
)I³
)I⁴
)I⁵
)I⁶
)IC¹
)IC²
)IC³
)IC⁴
)IC⁵
)IC⁶
)IN¹
)IN²
)IN³
)IN⁴
)IN⁵
)IN⁶
)K¹
)KC¹
)KN¹
)L¹
)LC¹
)LN¹
)M¹
)MC¹
)MN¹
)N¹
)NC¹
)NN¹
)O¹
)O²
)O³
)O⁴
)O⁵
)O⁶
)OC¹
)OC²
)OC³
)OC⁴
)OC⁵
)OC⁶
)ON¹
)ON²
)ON³
)ON⁴
)ON⁵
)ON⁶
)O₂¹
)O₂²
)O₂³
)O₂⁴
)O₂⁵
)O₂⁶
)O₂C¹
)O₂C²
)O₂C³
)O₂C⁴
)O₂C⁵
)O₂C⁶
)O₂N¹
)O₂N²
)O₂N³
)O₂N⁴
)O₂N⁵
)O₂N⁶
)O₃¹
)O₃²
)O₃³
)O₃⁴
)O₃⁵
)O₃⁶
)O₃C¹
)O₃C²
)O₃C³
)O₃C⁴
)O₃C⁵
)O₃C⁶
)O₃N¹
)O₃N²
)O₃N³
)O₃N⁴
)O₃N⁵
)O₃N⁶
)P¹
)PC¹
)PN¹
)Q¹
)QC¹
)QN¹
)R¹
)RC¹
)RN¹
)S¹
)SC¹
)SN¹
)T¹
)TC¹
)TN¹
)U¹
)U²
)U³
)U⁴
)U⁵
)U⁶
)UC¹
)UC²
)UC³
)UC⁴
)UC⁵
)UC⁶
)UN¹
)UN²
)UN³
)UN⁴
)UN⁵
)UN⁶
)U₂¹
)U₂²
)U₂³
)U₂⁴
)U₂⁵
)U₂⁶
)U₂C¹
)U₂C²
)U₂C³
)U₂C⁴
)U₂C⁵
)U₂C⁶
)U₂N¹
)U₂N²
)U₂N³
)U₂N⁴
)U₂N⁵
)U₂N⁶
)V¹
)VC¹
)VN¹
)X¹
)XC¹
)XN¹
)Y¹
)Y²
)Y³
)Y⁴
)Y⁵
)Y⁶
)YC¹
)YC²
)YC³
)YC⁴
)YC⁵
)YC⁶
)YN¹
)YN²
)YN³
)YN⁴
)YN⁵
)YN⁶
)local export = {}
local m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local lower = m_str_utils.lower
local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local u = m_str_utils.char
local upper = m_str_utils.upper
local a, b = u(0xF000), u(0xF001)
local diacritics = {
--[===[--Order given by Stephen G. Brown
= c, -- acute
= d, -- grave
= e, -- hook
= f, -- tilde
= g -- dot above]===]
-- Order given by Fumiko Take
= "!", -- grave
= "#", -- hook
= "$", -- tilde
= "%", -- acute
= "&" -- dot above
}
local oneChar = { -- separate letters
= "a" .. a, = "a" .. b, = "d" .. a, = "e" .. a, = "o" .. a, = "o" .. b, = "u" .. a
}
function export.makeSortKey(text, lang, sc)
text = gsub(lower(toNFD(text)), ".", diacritics)
text = gsub(text, "()(+)", "%2%1")
return upper(gsub(toNFC(text), ".", oneChar))
end
local vi = require("Module:languages").getByCode("vi")
local function tag(text)
return require("Module:script utilities").tag_text(text, vi)
end
local showsubst = {
= "₂", = "₃", = "²", = "³", = "⁴", = "⁵", = "⁶"
}
function export.showSortkey(frame)
local output = {}
for _, word in ipairs(frame.args) do
local sc = vi:findBestScript(word):getCode()
local sortkey = gsub(export.makeSortKey(word, "vi", sc), ".", showsubst)
sortkey = gsub(sortkey, "()$", "%1¹")
sortkey = gsub(sortkey, "()(%s)", "%1¹%2")
local example = "\n* <code>" .. sortkey .. "</code>\n: " .. tag(word)
table.insert(output, example)
end
return table.concat(output)
end
function export.showSorting(frame)
local terms = {}
for _, term in ipairs(frame.args) do
table.insert(terms, term)
end
local makeSortKey = require("Module:fun").memoize(export.makeSortKey)
local function comp(term1, term2)
return makeSortKey(term1) < makeSortKey(term2)
end
table.sort(terms, comp)
for i, term in pairs(terms) do
local sc = vi:findBestScript(term):getCode()
local sortkey = gsub(export.makeSortKey(term, "vi", sc), ".", showsubst)
sortkey = gsub(sortkey, "()$", "%1¹")
sortkey = gsub(sortkey, "()(%s)", "%1¹%2")
terms = "\n* " .. tag(term) .. " (<code>" .. sortkey .. "</code>)"
end
return table.concat(terms)
end
return export