မော်ဂျူး:NumberSpell
အပွိုင်အငုဲင်ꩻ
Documentation for this module may be created at မော်ဂျူး:NumberSpell/doc
-- This module converts a number into its written English form.
-- For example, "2" becomes "two", and "79" becomes "seventy-nine".
local getArgs = require('Module:Arguments').getArgs
local p = {}
local max = 100 -- The maximum number that can be parsed.
local ones = {
[0] = 'သုည',
[1] = 'တာ',
[2] = 'နီ',
[3] = 'သိုမ်',
[4] = 'လစ်ꩻ',
[5] = 'ငတ်ꩻ',
[6] = 'သူ',
[7] = 'နွုတ်ꩻ',
[8] = 'သွောစ်ꩻ',
[9] = 'ကွတ်ꩻ'
}
local specials = {
[10] = 'တဆီ',
[11] = 'တဆီပုဲင်',
[12] = 'တဆီနီ',
[13] = 'တဆီသိုမ်',
[15] = 'တဆီငတ်ꩻ',
[18] = 'တဆီသွောစ်ꩻ',
[20] = 'နီဆီ',
[30] = 'သိုမ်ဆီ',
[40] = 'လစ်ꩻဆီ',
[50] = 'ငတ်ꩻဆီ',
[60] = 'သူဆီ',
[70] = 'နွုတ်ꩻဆီ',
[80] = 'သွောစ်ꩻဆီ',
[90] = 'ကွတ်ꩻဆီ',
[100] = 'တရျာꩻ'
}
local formatRules = {
{num = 90, rule = 'ကွတ်ꩻဆီ-%s'},
{num = 80, rule = 'သွောစ်ꩻဆီ-%s'},
{num = 70, rule = 'နွုတ်ꩻဆီ-%s'},
{num = 60, rule = 'သူဆီ-%s'},
{num = 50, rule = 'ငတ်ꩻဆီ-%s'},
{num = 40, rule = 'လစ်ꩻဆီ-%s'},
{num = 30, rule = 'သိုမ်ဆီ-%s'},
{num = 20, rule = 'နီဆီ-%s'},
{num = 10, rule = '%ဆီ'}
}
function p.main(frame)
local args = getArgs(frame)
local num = tonumber(args[1])
local success, result = pcall(p._main, num)
if success then
return result
else
return string.format('<strong class="error">Error: %s</strong>', result) -- "result" is the error message.
end
return p._main(num)
end
function p._main(num)
if type(num) ~= 'number' or math.floor(num) ~= num or num < 0 or num > max then
error('input must be an integer between 0 and ' .. tostring(max), 2)
end
-- Check for numbers from 0 to 9.
local onesVal = ones[num]
if onesVal then
return onesVal
end
-- Check for special numbers.
local specialVal = specials[num]
if specialVal then
return specialVal
end
-- Construct the number from its format rule.
onesVal = ones[num % 10]
if not onesVal then
error('Unexpected error parsing input ' .. tostring(num))
end
for i, t in ipairs(formatRules) do
if num >= t.num then
return string.format(t.rule, onesVal)
end
end
error('No format rule found for input ' .. tostring(num))
end
return p