diff --git a/CRM/Admin/Form/Setting/Localization.php b/CRM/Admin/Form/Setting/Localization.php index 4273e9b98f55..d18e75ab718f 100644 --- a/CRM/Admin/Form/Setting/Localization.php +++ b/CRM/Admin/Form/Setting/Localization.php @@ -32,6 +32,7 @@ class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting { 'inheritLocale' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'lcMessages' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'legacyEncoding' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, + 'format_locale' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'monetaryThousandSeparator' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'monetaryDecimalPoint' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, 'moneyformat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, @@ -43,11 +44,9 @@ class CRM_Admin_Form_Setting_Localization extends CRM_Admin_Form_Setting { * Build the form object. */ public function buildQuickForm() { - $config = CRM_Core_Config::singleton(); - $this->setTitle(ts('Settings - Localization')); - $warningTitle = json_encode(ts("Warning")); + $warningTitle = json_encode(ts('Warning')); $defaultLocaleOptions = CRM_Admin_Form_Setting_Localization::getDefaultLocaleOptions(); if (CRM_Core_I18n::isMultiLingual()) { diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index f6ed3dcf0339..30cb0cb8eadc 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -239,6 +239,28 @@ public static function languages($justEnabled = FALSE) { return $justEnabled ? $enabled : $all; } + /** + * Get the options available for format locale. + * + * Note the pseudoconstant can't be used as the key is the name not the value. + * + * @return array + */ + public static function getFormatLocales(): array { + $values = CRM_Core_OptionValue::getValues(['name' => 'languages'], $optionValues, 'label', TRUE); + $return = []; + $return[NULL] = ts('Inherit from language'); + foreach ($values as $value) { + $return[$value['name']] = $value['label']; + } + // Sorry not sorry. + // Hacking in for now since the is probably the most important use-case for + // money formatting in an English speaking non-US locale based on any reasonable + // metric. + $return['en_NZ'] = ts('English (New Zealand)'); + return $return; + } + /** * Return the available UI languages * @return array|string diff --git a/Civi/Core/Format.php b/Civi/Core/Format.php index 582727cce57a..b3076d0e8dc6 100644 --- a/Civi/Core/Format.php +++ b/Civi/Core/Format.php @@ -43,7 +43,7 @@ public function money($amount, ?string $currency = NULL, ?string $locale = NULL) $currency = Civi::settings()->get('defaultCurrency'); } if (!isset($locale)) { - $locale = CRM_Core_I18n::getLocale(); + $locale = Civi::settings()->get('format_locale') ?? CRM_Core_I18n::getLocale(); } $money = Money::of($amount, $currency, NULL, RoundingMode::HALF_UP); $formatter = $this->getMoneyFormatter($currency, $locale); @@ -150,7 +150,7 @@ public function moneyNumberLong($amount, ?string $currency, ?string $locale): st * we are looking at how to manage an 'opt in' */ protected function isUseSeparatorSettings(): bool { - return !CRM_Utils_Constant::value('IGNORE_SEPARATOR_CONFIG'); + return !Civi::settings()->get('format_locale') && !CRM_Utils_Constant::value('IGNORE_SEPARATOR_CONFIG'); } /** diff --git a/settings/Localization.setting.php b/settings/Localization.setting.php index ec1be4f3bbfc..6a55c01d981d 100644 --- a/settings/Localization.setting.php +++ b/settings/Localization.setting.php @@ -409,6 +409,27 @@ 'callback' => 'CRM_Core_I18n::languages', ], ], + 'format_locale' => [ + 'group_name' => 'Localization Preferences', + 'group' => 'localization', + 'name' => 'format_locale', + 'type' => 'String', + 'quick_form_type' => 'Select', + 'html_type' => 'Select', + 'html_attributes' => [ + 'class' => 'crm-select2', + ], + 'default' => NULL, + 'add' => '5.47', + 'title' => ts('Formatting locale'), + 'is_domain' => 1, + 'is_contact' => 0, + 'help_text' => NULL, + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_I18n::getFormatLocales', + ], + 'description' => ts('Locale to use when formatting money (and in future dates). This replaces thousandsSeparator & decimalSeparator & moneyFormat settings.'), + ], 'uiLanguages' => [ 'group_name' => 'Localization Preferences', 'group' => 'localization', diff --git a/templates/CRM/Admin/Form/Setting/Localization.tpl b/templates/CRM/Admin/Form/Setting/Localization.tpl index 754212bc0e12..05fd577a9b32 100644 --- a/templates/CRM/Admin/Form/Setting/Localization.tpl +++ b/templates/CRM/Admin/Form/Setting/Localization.tpl @@ -49,10 +49,15 @@ {$settings_fields.contact_default_language.description} - - {$form.defaultCurrency.label} {help id='defaultCurrency' title=$form.defaultCurrency.label} - {$form.defaultCurrency.html} - + + {$form.defaultCurrency.label} {help id='defaultCurrency' title=$form.defaultCurrency.label} + {$form.defaultCurrency.html} + + + {$form.format_locale.label} + {$form.format_locale.html}
+ {ts}Locale to use when formatting money (and in future dates). This replaces thousandsSeparator & decimalSeparator settings.{/ts} + {$form.monetaryThousandSeparator.label} {$form.monetaryThousandSeparator.html}