-- 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}