Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.0.8
-
Fix Version/s: 4.2.0
-
Component/s: None
-
Labels:None
Description
When the CiviCRM interface is in French (or, I suppose, any other language using a non-ascii latin alphabet), the list of countries in, for example, "billing information" block of a contribute form, will list the countries that start with a non-ascii caracter at the end of the list.
How to reproduce:
- enable all countries in CiviCRM locale config
- set the default interface language to French
- view the contribution form: in the list of countries, États-Unis (USA) will be amongst the last countries, instead of being after Estonie.
This seems to be caused by the fact that asort() does not respect the locale, in CRM/Core/PseudoConstant.php country().
I tried doing a setlocale(), but it did not work (even if my locales are set correctly on the operating system).
My fix was to use a PHP "Collator" class from the php5-intl package.
$lcMessages = CRM_Utils_System::getUFLocale();
$countries = CRM_Core_PseudoConstant::country();
$collator = new Collator($lcMessages . '.utf8');
$collator->asort($countries);
For more information, see the hook_civicrm_buildForm in https://github.com/mlutfy/civicrm_l10n/blob/master/civicrm_l10n.module
Given that this depends on the php5-intl package, I can understand that you might not want to depend on Collate for sorting, but it would be nice to have a hook so that it would be easier to override. Or code a CRM_Utils_Array::asort() ?