是否有一种干净的方式来显示前端所有数字的阿拉伯数字(价格,分页......)?我试图将英语转换为阿拉伯语但仍需要一些修复(priceBox的问题..)。
我已覆盖 Magento \ Directory \ Model \ PriceCurrency 并替换format()函数以根据商店lang返回阿拉伯数字(I' ve En + Ar):
public function format(
$amount,
$includeContainer = true,
$precision = self::DEFAULT_PRECISION,
$scope = null,
$currency = null
) {
$currentStore = $this->store->getLocale();
if($currentStore == 'en_US'){
return $this->getCurrency($scope, $currency)
->formatPrecision($amount, $precision, [], $includeContainer);
}else{
$western_arabic = array('0','1','2','3','4','5','6','7','8','9');
$eastern_arabic = array('٠','١','٢','٣','٤','٥','٦','٧','٨','٩');
return str_replace($western_arabic, $eastern_arabic, $this->getCurrency($scope, $currency)
->formatPrecision($amount, $precision, [], $includeContainer));
}
}
这适用于类别页面,但不适用于产品页面!搜索之后,我发现有一个Javascript代码(PriceBox!)用
require([
'jquery',
'priceBox'
], function($){
var dataPriceBoxSelector = '[data-role=priceBox]',
dataProductIdSelector = '[data-product-id=<?php echo $block->escapeHtml($_product->getId())?>]',
priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);
priceBoxes = priceBoxes.filter(function(index, elem){
return !$(elem).find('.price-from').length;
});
priceBoxes.priceBox({'priceConfig': <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>});
});
我测试过在JS代码之后添加一个setTimeout但是,这不是一个正确的方法因为用户价格从ar&gt;改变了en&gt;再次:
setTimeout(function(){
var price = $('.price').html();
String.prototype.toIndiaDigits= function(){
var id= ['۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'];
return this.replace(/[0-9]/g, function(w){
return id[+w]
});
}
$('.price').html(price.toIndiaDigits());
}, 1000);
关于magento 2的价格和前端的实用程序: How is a price rendered on a frontend product view page in Magento 2
是否有任何干净的方法来实现(阿拉伯商店的阿拉伯数字)?感谢您对此的帮助。