मोड्युल:CvtDigit
स्वरूप
उद्देश्य
[सम्पादन गर्नुहोस्]यस मोड्युलको उद्देश्य स्थानीय अङ्कहरूलाई अङ्ग्रेजी र अङ्ग्रेजी अङ्कहरूलाई स्थानीय अङ्कहरूमा परिवर्तन गर्ने हो। यसको प्रयोगले अङ्क परिवर्तन सहज हुनेछ।
प्रयोग
[सम्पादन गर्नुहोस्]स्थानीय अङ्कहरूलाई अङ्ग्रेजीमा परिवर्तन
{{#invoke:CvtDigit|main|<!-- your number here -->|to_en}}
- उदाहरणका लागि,
{{#invoke:CvtDigit|main|२०१९|to_en}}ले "2019" दिन्छ।
अङ्ग्रेजी अङ्कहरूलाई स्थानीय अङ्कहरूमा परिवर्तन
{{#invoke:CvtDigit|main|<!-- your number here -->|to_local}}
- उदाहरणका लागि,
{{#invoke:CvtDigit|main|2019|to_local}}ले "२०१९" दिन्छ।
-- 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}