มอดูล:Th-utilities
หน้าตา
เอกสารการใช้งานสำหรับมอดูลนี้อาจสร้างขึ้นที่ มอดูล:Th-utilities/doc
local export = {}
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local thai_digits = {"๐", "๑", "๒", "๓", "๔", "๕", "๖", "๗", "๘", "๙"}
local thai_words = {"ศูนย์", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า"}
local thai_words2 = {["."]="จุด",["-"]="ขีด",["+"]="บวก",["−"]="ลบ",["/"]="ทับ"}
function export.arabic_digit_to_thai(text)
if type(text) == "number" then
text = tostring(text) -- convert to string
end
if type(text) == "string" and find(text, "[0-9]") then
for n = 0, 9 do
text = gsub(text, tostring(n), thai_digits[n + 1])
end
end
return text
end
function export.thai_digit_to_arabic(text)
if type(text) == "string" and find(text, "[๐-๙]") then
for n = 0, 9 do
text = gsub(text, thai_digits[n + 1], tostring(n))
end
end
return text
end
function export.thai_number_sequence(text)
if type(text) == "number" then
text = tostring(text) -- convert to string
end
if type(text) == "string" then
text = export.thai_digit_to_arabic(text)
for n = 0, 9 do
text = gsub(text, tostring(n), thai_words[n + 1])
end
text = gsub(text, ".", thai_words2)
end
return text
end
return export