मॉड्यूल:Number converter
दिखावट
लुआ त्रुटि मॉड्यूल:Documentation में पंक्ति 144 पर: message: type error in message cfg.container (string expected, got nil)।
--[=[ Converts given hindi number to English or English number to hindi
]=]
local p = {}
function p._translate2hi(text)
if type(text) == 'string' then
text = text:gsub('%d', {
['0'] = '०',
['1'] = '१',
['2'] = '२',
['3'] = '३',
['4'] = '४',
['5'] = '५',
['6'] = '६',
['7'] = '७',
['8'] = '८',
['9'] = '९',
})
end
return text
end
function p._translate2en(text)
if type(text) == 'string' then
text = mw.ustring.gsub(text, '%d', {
['०'] = '0',
['१'] = '1',
['२'] = '2',
['३'] = '3',
['४'] = '4',
['५'] = '5',
['६'] = '6',
['७'] = '7',
['८'] = '8',
['९'] = '9',
})
end
return text
end
function p.convert(lang, text)
if lang == 'hi' then
return p._translate2bn(text)
end
if lang == 'en' then
return p._translate2en(text)
end
return text
end
function p.translate2hi(frame)
local text = frame.args[1] or frame:getParent().args[1]
return p._translate2hi(text)
end
function p.translate2en(frame)
local text = frame.args[1] or frame:getParent().args[1]
return p._translate2en(text)
end
function p.convert_template(frame)
local args = frame.args
local pargs = frame:getParent().args
local lang = args[1] or pargs[1]
local text = args[2] or pargs[2]
return p.convert(lang, text)
end
return p