Skip to content

Commit cb1719f

Browse files
authored
Merge pull request #5863 from magento-tango/TANGO-PR-07-08-2020-v24
TANGO-PR-07-08-2020-v24
2 parents 4b75b15 + 3399875 commit cb1719f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/internal/Magento/Framework/Locale/Format.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ class Format implements \Magento\Framework\Locale\FormatInterface
1515
*/
1616
private const JAPAN_LOCALE_CODE = 'ja_JP';
1717

18+
/**
19+
* Arab locale code
20+
*/
21+
private const ARABIC_LOCALE_CODES = [
22+
'ar_DZ',
23+
'ar_EG',
24+
'ar_KW',
25+
'ar_MA',
26+
'ar_SA',
27+
];
28+
1829
/**
1930
* @var \Magento\Framework\App\ScopeResolverInterface
2031
*/
@@ -73,6 +84,11 @@ public function getNumber($value)
7384
return (float)$value;
7485
}
7586

87+
/** Normalize for Arabic locale */
88+
if (in_array($this->_localeResolver->getLocale(), self::ARABIC_LOCALE_CODES)) {
89+
$value = $this->normalizeArabicLocale($value);
90+
}
91+
7692
//trim spaces and apostrophes
7793
$value = preg_replace('/[^0-9^\^.,-]/m', '', $value);
7894

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

164180
return $result;
165181
}
182+
183+
/**
184+
* Normalizes the number of Arabic locale.
185+
*
186+
* Substitutes Arabic thousands grouping and Arabic decimal separator symbols (U+066C, U+066B)
187+
* with common grouping and decimal separator
188+
*
189+
* @param string $value
190+
* @return string
191+
*/
192+
private function normalizeArabicLocale($value): string
193+
{
194+
$arabicGroupSymbol = '٬';
195+
$arabicDecimalSymbol = '٫';
196+
$value = str_replace([$arabicGroupSymbol, $arabicDecimalSymbol], [',', '.'], $value);
197+
198+
return $value;
199+
}
166200
}

lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public function provideNumbers(): array
146146
['2,054.00', 2054],
147147
['4,000', 4000.0, 'ja_JP'],
148148
['4,000', 4.0, 'en_US'],
149+
['2٬599٫50', 2599.50, 'ar_EG'],
150+
['2٬000٬000٫99', 2000000.99, 'ar_SA'],
149151
];
150152
}
151153
}

0 commit comments

Comments
 (0)