Generates lists of items in Min Nan pronunciation data modules, such as Module:zh/data/nan-pron/000.
local export = {}
local sortedPairs = require("Module:table").sortedPairs
local UTF8_char = "*"
-- Based on tone_to_mark in ], but omits final stops.
local tone_to_number = {
= "1",
= "2",
= "3",
= "5",
= "6",
= "7",
= "8",
= "9",
}
local decompose = mw.ustring.toNFD
local prepare = require("Module:memoize")(function(item) -- Converts tones to numbers and hopefully puts them at end of syllable.
return decompose(item)
:lower()
:gsub(UTF8_char, tone_to_number)
:gsub("()(+)", "%2%1")
:gsub("()ⁿ", "ⁿ%1")
end, true)
local function compare(item1, item2)
return prepare(item1) < prepare(item2)
end
local function add(t, v)
t.n = t.n + 1
t = v
end
function export.show(frame)
local number = frame.args
local list = require("Module:zh/data/nan-pron/"..number)
local results = {}
local old_module = number == "-019"
if old_module then
for key in sortedPairs(list, compare) do
local current = prepare(key:match(UTF8_char))
if not results then
results = ""
else
results = results .. "] "
end
end
else
-- Key is Han characters, value is Pe̍h-ōe-jī.
for key, val in sortedPairs(list, compare) do
local current = prepare(val:match(UTF8_char))
if not results then
results = { n = 0 }
else
add(results, "]")
end
end
end
local result = {}
local i = 0
if old_module then
for _, val in sortedPairs(results) do
i = i + 1
result = val
end
else
for _, val in sortedPairs(results) do
i = i + 1
result = table.concat(val, " ")
end
end
return table.concat(result, "\n\n")
end
return export