Skip to content

Commit

Permalink
Merge pull request #27970 from eileenmcnaughton/money_format
Browse files Browse the repository at this point in the history
Move the locale default getting from the money() function to the getFormatter function
  • Loading branch information
mattwire authored Oct 30, 2023
2 parents 65bd460 + 8af3735 commit 5a7b6fa
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Civi/Core/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public function money($amount, ?string $currency = NULL, ?string $locale = NULL)
if (!$currency) {
$currency = Civi::settings()->get('defaultCurrency');
}
if (!isset($locale)) {
global $civicrmLocale;
$locale = $civicrmLocale->moneyFormat ?? (Civi::settings()->get('format_locale') ?? CRM_Core_I18n::getLocale());
}
$currencyObject = CRM_Utils_Money::getCurrencyObject($currency);
$money = Money::of($amount, $currencyObject, NULL, RoundingMode::HALF_UP);
$formatter = $this->getMoneyFormatter($currency, $locale);
Expand Down Expand Up @@ -92,7 +88,7 @@ public function number($amount, ?string $locale = NULL, array $attributes = [
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
public function moneyNumber($amount, string $currency, $locale): string {
public function moneyNumber($amount, string $currency, $locale = NULL): string {
if (($amount = $this->checkAndConvertAmount($amount)) === '') {
return '';
}
Expand Down Expand Up @@ -195,9 +191,7 @@ protected function isUseSeparatorSettings(): bool {
}

/**
* Get the money formatter for when we are using configured thousand separators.
*
* Our intent is to phase out these settings in favour of deriving them from the locale.
* Get the cached money formatter.
*
* @param string|null $currency
* @param string|null $locale
Expand All @@ -215,7 +209,10 @@ public function getMoneyFormatter(?string $currency = NULL, ?string $locale = NU
if (!$currency) {
$currency = Civi::settings()->get('defaultCurrency');
}
$locale = $locale ?: \Civi\Core\Locale::detect()->moneyFormat;
if (!isset($locale)) {
global $civicrmLocale;
$locale = $civicrmLocale->moneyFormat ?? (Civi::settings()->get('format_locale') ?? CRM_Core_I18n::getLocale());
}

$cacheKey = __CLASS__ . $currency . '_' . $locale . '_' . $style . (!empty($attributes) ? md5(json_encode($attributes)) : '');
if (!isset(\Civi::$statics[$cacheKey])) {
Expand Down

0 comments on commit 5a7b6fa

Please sign in to comment.