Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into TANGO-PR-07-08-2020-v24
  • Loading branch information
Roman Lytvynenko committed Jul 8, 2020
2 parents 735579d + 76e011a commit 3399875
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/internal/Magento/Framework/Locale/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class Format implements \Magento\Framework\Locale\FormatInterface
*/
private const JAPAN_LOCALE_CODE = 'ja_JP';

/**
* Arab locale code
*/
private const ARABIC_LOCALE_CODES = [
'ar_DZ',
'ar_EG',
'ar_KW',
'ar_MA',
'ar_SA',
];

/**
* @var \Magento\Framework\App\ScopeResolverInterface
*/
Expand Down Expand Up @@ -73,6 +84,11 @@ public function getNumber($value)
return (float)$value;
}

/** Normalize for Arabic locale */
if (in_array($this->_localeResolver->getLocale(), self::ARABIC_LOCALE_CODES)) {
$value = $this->normalizeArabicLocale($value);
}

//trim spaces and apostrophes
$value = preg_replace('/[^0-9^\^.,-]/m', '', $value);

Expand Down Expand Up @@ -163,4 +179,22 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)

return $result;
}

/**
* Normalizes the number of Arabic locale.
*
* Substitutes Arabic thousands grouping and Arabic decimal separator symbols (U+066C, U+066B)
* with common grouping and decimal separator
*
* @param string $value
* @return string
*/
private function normalizeArabicLocale($value): string
{
$arabicGroupSymbol = '٬';
$arabicDecimalSymbol = '٫';
$value = str_replace([$arabicGroupSymbol, $arabicDecimalSymbol], [',', '.'], $value);

return $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public function provideNumbers(): array
['2,054.00', 2054],
['4,000', 4000.0, 'ja_JP'],
['4,000', 4.0, 'en_US'],
['2٬599٫50', 2599.50, 'ar_EG'],
['2٬000٬000٫99', 2000000.99, 'ar_SA'],
];
}
}

0 comments on commit 3399875

Please sign in to comment.