1

I have two store

  1. English
  2. Arabic

In Arabic stores, product prices or other custom prices are shown in Arabic numbers instead of English numbers.

like

٥٠٫٠٠$

only the Product details page price shows correctly.

how we can show English numbers in both stores?

4 Answers 4

0

Step:1 Create di.xml {vendore_name}/{module_name}/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Directory\Model\Currency">
        <plugin name="currency_format" type="{vendore_name}\{module_name}\Model\Currency" />
    </type>       
</config>

Step:-2 Craete plugin file Currency.php {vendore_name}/{module_name}/Model/Currency.php

<?php
namespace {vendore_name}\{module_name}\Model;

use Magento\Framework\Locale\CurrencyInterface;
use Magento\Framework\Locale\FormatInterface;
  
class Currency
{
    /**
     * @var FormatInterface
     */
    private $localeFormat;
    /**
     * @var CurrencyInterface
     */
    private $localeCurrency;

    /**
     * Currency constructor.
     *
     * @param FormatInterface $localeFormat
     * @param CurrencyInterface $localeCurrency
     */
    public function __construct(
        CurrencyInterface $localeCurrency,
        FormatInterface $localeFormat

    ) {

        $this->localeFormat = $localeFormat;
        $this->localeCurrency = $localeCurrency;
    }

    public function aroundFormatTxt(
        \Magento\Directory\Model\Currency $subject,
        callable $proceed,
        $price,
        $options = []
    ) {
        if (!is_numeric($price)) {
            $price = $this->localeFormat->getNumber($price);
        }

        $price = sprintf("%F", $price);

        return $this->localeCurrency->getCurrency($subject->getCode())->toCurrency($price, $options);
    }

}
0

you can see this file:-

vendor/magento/zendframework1/library/Zend/Locale/Data/numberingSystems.xml

and change the first line to be as following:-

<numberingSystem id="arab" type="numeric" digits="0123456789"/>
0

I'm facing same issue before. We can resolve this translation issue by do changes in following two files:-

1] Create plugin for change currency position as following:

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Trek_Repositionprice',
    __DIR__
);

etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Trek_Repositionprice" setup_version="1.0.0">
    </module>
</config>

etc/di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Directory\Model\Currency">
        <plugin name="change_currency_position"
            type="Trek\Repositionprice\Plugin\ChangeCurrencyPosition"/>
    </type>
</config>

Plugin/ChangeCurrencyPosition.php

<?php

namespace Trek\Repositionprice\Plugin;

class ChangeCurrencyPosition
{
    /**
     * Change currency position
     *
     * @param \Magento\Directory\Model\Currency $subject
     * @param float $price
     * @param array $options
     * @return array|array[]
     */
    public function beforeFormatTxt(
        \Magento\Directory\Model\Currency $subject,
        $price,
        $options = []
    ) {
        $options['position'] = 16; // 16 is for Right position, 8 is for Standard position and 32 is for Left position
        return [$price,$options];
    }
}

2] If still after create above plugin whole price coverted in wrong format then we need to override price-utils.js file as below:-

  • Just copy /vendor/magento/module-catalog/view/base/web/js/price-utils.js file into your custom theme directory for ex app/design/frontend/Namespace/Themename/Magento_Catalog/web/js/price-utils.js

  • Here window.LOCALE condition which converts whole price into particular locale language

enter image description here

After removed window.LOCALEcondition price translation working proper.

enter image description here

Hope it works. Thanks.

0

you need to make pluggin for this class

Magento\Framework\Currency\Data\Currency 

at this function

setLocale

and check if is it arabic make the country other

[![code area][1]][1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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