dev/translation#71 getFullMonthNames: do not rely on the operating system locale...
authorMathieu Lutfy <mathieu@symbiotic.coop>
Mon, 16 Aug 2021 15:41:45 +0000 (11:41 -0400)
committerMathieu Lutfy <mathieu@bidon.ca>
Sat, 4 Sep 2021 14:47:04 +0000 (10:47 -0400)
CRM/Report/Form.php
CRM/Utils/Date.php

index 1e297cbb83c60a2ac472148f6bdcc6388a5bd8e2..352bbf35eccf2cf47ccf7b57aff3f846c51dceaa 100644 (file)
@@ -1361,20 +1361,8 @@ class CRM_Report_Form extends CRM_Core_Form {
               !is_array($field['options']) || empty($field['options'])
             ) {
               // If there's no option list for this filter, define one.
-              $field['options'] = [
-                1 => ts('January'),
-                2 => ts('February'),
-                3 => ts('March'),
-                4 => ts('April'),
-                5 => ts('May'),
-                6 => ts('June'),
-                7 => ts('July'),
-                8 => ts('August'),
-                9 => ts('September'),
-                10 => ts('October'),
-                11 => ts('November'),
-                12 => ts('December'),
-              ];
+              $field['options'] = CRM_Utils_Date::getFullMonthNames();
+
               // Add this option list to this column _columns. This is
               // required so that filter statistics show properly.
               $this->_columns[$table]['filters'][$fieldName]['options'] = $field['options'];
index 093862b8449ce954dd0c459447dff8131720c810..632eb4910bbafd25080a7d9159f8f849615df7e7 100644 (file)
@@ -237,16 +237,27 @@ class CRM_Utils_Date {
    *
    */
   public static function &getFullMonthNames() {
-    static $fullMonthNames;
-    if (!isset($fullMonthNames)) {
-
-      // set LC_TIME and build the arrays from locale-provided names
-      CRM_Core_I18n::setLcTime();
-      for ($i = 1; $i <= 12; $i++) {
-        $fullMonthNames[$i] = strftime('%B', mktime(0, 0, 0, $i, 10, 1970));
-      }
+    if (empty(\Civi::$statics[__CLASS__]['fullMonthNames'])) {
+      // Not relying on strftime because it depends on the operating system
+      // and most people will not have a non-US locale configured out of the box
+      // Ignoring other date names for now, since less visible by default
+      \Civi::$statics[__CLASS__]['fullMonthNames'] = [
+        1 => ts('January'),
+        2 => ts('February'),
+        3 => ts('March'),
+        4 => ts('April'),
+        5 => ts('May'),
+        6 => ts('June'),
+        7 => ts('July'),
+        8 => ts('August'),
+        9 => ts('September'),
+        10 => ts('October'),
+        11 => ts('November'),
+        12 => ts('December'),
+      ];
     }
-    return $fullMonthNames;
+
+    return \Civi::$statics[__CLASS__]['fullMonthNames'];
   }
 
   /**