This is a minimal patch to address https://lab.civicrm.org/dev/core/-/issues/3095
in time for 5.47. With this set it is possible to change the format locale to
English, Canada or English, Australian (but not NZ!)
and the currency will only be displayed before dollar amounts NOT of that
currency.
This should be enough to mitigate that regression feeling but missing are
1) fixing the admin form to hide irrelevant settings if format_locale is set
2) the psuedoconstant is cludgey - existing stuff doesn't seem to work so
I added a function - also - if we ARE going to use this option group we
should .... add NZ to it
'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,
* 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()) {
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 getLocaleOptions(): array {
+ $values = CRM_Core_OptionValue::getValues(['name' => 'languages'], $optionValues, 'label', TRUE);
+ foreach ($values as $value) {
+ $return[$value['name']] = $value['label'];
+ }
+ return $return;
+ }
+
/**
* Return the available UI languages
* @return array|string
$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);
* 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');
}
/**
'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' => [
+ 'multiple' => 0,
+ '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::getLocaleOptions',
+ ],
+ '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',
<span class="description">{$settings_fields.contact_default_language.description}</span>
</td>
</tr>
- <tr class="crm-localization-form-block-defaultCurrency">
- <td class="label">{$form.defaultCurrency.label} {help id='defaultCurrency' title=$form.defaultCurrency.label}</td>
- <td>{$form.defaultCurrency.html}</td>
- </tr>
+ <tr class="crm-localization-form-block-defaultCurrency">
+ <td class="label">{$form.defaultCurrency.label} {help id='defaultCurrency' title=$form.defaultCurrency.label}</td>
+ <td>{$form.defaultCurrency.html}</td>
+ </tr>
+ <tr class="crm-localization-form-block-format_locale">
+ <td class="label">{$form.format_locale.label}</td>
+ <td>{$form.format_locale.html}<br />
+ <span class="description">{ts}Locale to use when formatting money (and in future dates). This replaces thousandsSeparator & decimalSeparator settings.{/ts}</span></td>
+ </tr>
<tr class="crm-localization-form-block-monetaryThousandSeparator">
<td class="label">{$form.monetaryThousandSeparator.label}</td>
<td>{$form.monetaryThousandSeparator.html}</td>