1

how to convert English numbers to persian/arabic numbers in Magento? (in all frontend)

i got this but i don't know how to use it or where to copy it.

function fanum($englishnumbers)
{
$englishnumbers = str_replace(’0′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’1′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’2′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’3′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’4′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’5′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’6′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’7′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’8′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’9′ , ‘PN’ , $englishnumbers);

return $englishnumbers;
}

"PN" will replaced by "persian or arabic numbers"

3

Simple solution would be to use Javascript. Since prices are wrapped in a span tag with some class/id. You can read those values and convert it to arabic number using window load event.

For english to arabic number conversion You can use some jQuery plugins:
http://www.jqueryscript.net/other/jQuery-Plugin-To-Convert-English-Numbers-To-Persian-persianumber.html

Solution:
File: app/design/frontend/[your-package]/[your-theme]/template/page/footer.phtml
Code:

<script type="text/javascript" src="<?php echo $this->getJsUrl('persianumber.min.js') ?>"></script>
<script type="text/javascript">
    jQuery.noConflict();
    jQuery(function(){
       jQuery('.price').persiaNumber('ar');
    });
</script>

Notes:
- Upload the jQuery plugin file: persianumber.min.js to js/ folder
- If you haven't loaded the jQuery file then load it.

  • thank you. but can you tell me how to apply it in magento? i mean where to exactly copy that. im new in magento. can you give details? @MagePsycho – Moh3n Jul 28 '14 at 6:23
  • 1
    @Moh3n I have edited my Answer. Please check. – MagePsycho Jul 28 '14 at 7:43
  • how can i apply it for other pages like onepagecheckout or else? – Moh3n Jul 29 '14 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.