Jump to content

Module:Convert to eastern arabic numerals

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TartarTorte (talk | contribs) at 03:13, 28 December 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local conversion_table = {
	['0'] = '٠',
	['1'] = '١',
	['2'] = '٢',
	['3'] = '٣',
	['4'] = '٤',
	['5'] = '٥',
	['6'] = '٦',
	['7'] = '٧',
	['8'] = '٨',
	['9'] = '٩',
	['%.'] = ','
}

function p.convert_str(num_str)
	for western, eastern in pairs(conversion_table) do
		num_str = string.gsub(num_str, western, eastern)
	end
	return num_str
end

function p.convert(frame)
	if frame.args == nil then 
		return nil 
	end
	local num_str = tostring(frame.args[1])
	return p.convert_str(num_str)
end

return p