Documentation for this module may be created at ಮೋಡ್ಯೂಲ್:CvtDigit/doc

-- Return input text after converting any local digits to en digits and vice-versa.
local ustring = mw.ustring

local local_to_en_digits = {
	['೦'] = '0',
	['೧'] = '1',
	['೨'] = '2',
	['೩'] = '3',
	['೪'] = '4',
	['೫'] = '5',
	['೬'] = '6',
	['೭'] = '7',
	['೮'] = '8',
	['೯'] = '9',
}

local en_to_local_digits = {
	['0'] = '೦',
	['1'] = '೧',
	['2'] = '೨',
	['3'] = '೩',
	['4'] = '೪',
	['5'] = '೫',
	['6'] = '೬',
	['7'] = '೭',
	['8'] = '೮',
	['9'] = '೯',
}

local function _main(input,conversion)
	-- Callable from another module.
	input = input or ''
	
	if conversion=="to_en" then
		text = ustring.gsub(input, '%d', local_to_en_digits)
		return text
	elseif conversion=="to_local" then
		text = input:gsub('%d', en_to_local_digits)
		return text
	else 
		return input 
	end
end

local function main(frame)
	-- Callable from #invoke or from a template.
	local text, conversion = frame.args[1] or frame:getParent().args[1], frame.args[2] or frame:getParent().args[2]
	-- call _main function for conversion process
	return _main(text, conversion)
end

return { main = main, _main = _main}