မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:mnw-utilities

နူ ဝိက်ရှေန်နရဳ

Documentation for this module may be created at မဝ်ဂျူ:mnw-utilities/doc

local export = {}

local gsub = mw.ustring.gsub
local find = mw.ustring.find
local match = mw.ustring.match
local mon_digits = {"၀", "၁", "၂", "၃", "၄", "၅", "၆", "၇", "၈", "၉"}

function export.pluralize(str)
	return str:find("ဂမၠိုင်$") and str or str .. "ဂမၠိုင်"
end

function export.arabic_digit_to_mon(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), mon_digits[n + 1])
		end
	end
	return text
end

function export.mon_digit_to_arabic(text)
	if type(text) == "string" and find(text, "[၀-၉]") then
		for n = 0, 9 do
			text = gsub(text, mon_digits[n + 1], tostring(n))
		end
	end
	return text
end

return export