Skip to content

Commit

Permalink
Add test for intl currency symbol as suffix + non-breaking space fix …
Browse files Browse the repository at this point in the history
…for intl symbol
  • Loading branch information
pelmered committed May 11, 2024
1 parent 9d8cef8 commit 69c7166
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/MoneyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ private static function getNumberFormatter(string $locale, int $style): NumberFo
if ($config['intl_currency_symbol']) {
$intlCurrencySymbol = $numberFormatter->getSymbol(NumberFormatter::INTL_CURRENCY_SYMBOL);
if ($numberFormatter->getTextAttribute(NumberFormatter::POSITIVE_PREFIX) !== '') {
$numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_PREFIX, $intlCurrencySymbol.' ');
// "\xc2\xa0" is a non-breaking space
$numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_PREFIX, $intlCurrencySymbol."\xc2\xa0");
}
if ($numberFormatter->getTextAttribute(NumberFormatter::POSITIVE_SUFFIX) !== '') {
$numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_SUFFIX, ' '.$intlCurrencySymbol);
// "\xc2\xa0" is a non-breaking space
$numberFormatter->setTextAttribute(NumberFormatter::POSITIVE_SUFFIX, "\xc2\xa0".$intlCurrencySymbol);
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/MoneyFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,14 @@ public function testInternationalCurrencySymbol()
MoneyFormatter::format(100000, new Currency('USD'), 'en_US')
);
}

public function testInternationalCurrencySymbolSuffix()
{
config(['filament-money-field.intl_currency_symbol' => true]);

self::assertSame(
self::replaceNonBreakingSpaces('1 000,00 SEK'),
MoneyFormatter::format(100000, new Currency('EUR'), 'sv_SE')
);
}
}

0 comments on commit 69c7166

Please sign in to comment.