Define gettext translation for world_region
authoreileen <emcnaughton@wikimedia.org>
Mon, 3 Dec 2018 01:44:13 +0000 (14:44 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 3 Dec 2018 22:57:32 +0000 (11:57 +1300)
CRM/Core/BAO/Address.php
CRM/Core/CodeGen/Specification.php
CRM/Core/DAO/Address.php
CRM/Core/DAO/Country.php
CRM/Core/PseudoConstant.php
xml/schema/Core/Address.xml
xml/schema/Core/Country.xml
xml/templates/dao.tpl

index 338712adfba5c76e3db0b4d169cbb41d570d37bd..a49737ad30cdcdc1f0cc377fdf5e3e8244325bc1 100644 (file)
@@ -1349,7 +1349,7 @@ SELECT is_primary,
       case 'world_region':
       case 'worldregion':
       case 'worldregion_id':
-        return CRM_Core_PseudoConstant::worldRegion();
+        return CRM_Core_BAO_Country::buildOptions('region_id', $context);
     }
     return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
   }
index 6d15ae5e0ebf59d42166fc8c3c6c38a4dc9c1b6d..faaaacce7deb337439c250f85a3487dbed6bcd05 100644 (file)
@@ -403,7 +403,9 @@ class CRM_Core_CodeGen_Specification {
         $field['widget']['required'] = $this->value('required', $fieldXML);
       }
     }
-
+    if (isset($fieldXML->localize_context)) {
+      $field['localize_context'] = $fieldXML->localize_context;
+    }
     $field['pseudoconstant'] = $this->value('pseudoconstant', $fieldXML);
     if (!empty($field['pseudoconstant'])) {
       //ok this is a bit long-winded but it gets there & is consistent with above approach
index 98677499ef7bdf0e113864c28930e3a7b67aa1b2..0f7e94aa5fe90e5874def33c3ab90ccb69f9a98b 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Core/Address.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:7e4fc550c624fb3f273f3b2f53a23ee3)
+ * (GenCodeChecksum:a81d4789f6650c68145ab9bf1e4481a8)
  */
 
 /**
@@ -585,6 +585,7 @@ class CRM_Core_DAO_Address extends CRM_Core_DAO {
           'entity' => 'Address',
           'bao' => 'CRM_Core_BAO_Address',
           'localizable' => 0,
+          'localize_context' => 'province',
           'FKClassName' => 'CRM_Core_DAO_StateProvince',
           'html' => [
             'type' => 'ChainSelect',
@@ -656,6 +657,7 @@ class CRM_Core_DAO_Address extends CRM_Core_DAO {
           'entity' => 'Address',
           'bao' => 'CRM_Core_BAO_Address',
           'localizable' => 0,
+          'localize_context' => 'country',
           'FKClassName' => 'CRM_Core_DAO_Country',
           'html' => [
             'type' => 'Select',
index 2860eaf0617ade4f8e4296012534897887983273..5f31cab89bded11c529ecd1550786fea8104b999 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Core/Country.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:a71fa14f07c9291cf9db0e2335ee4613)
+ * (GenCodeChecksum:467cb92fabf3d936d330591eec94504d)
  */
 
 /**
@@ -220,7 +220,13 @@ class CRM_Core_DAO_Country extends CRM_Core_DAO {
           'entity' => 'Country',
           'bao' => 'CRM_Core_BAO_Country',
           'localizable' => 0,
+          'localize_context' => 'country',
           'FKClassName' => 'CRM_Core_DAO_Worldregion',
+          'pseudoconstant' => [
+            'table' => 'civicrm_worldregion',
+            'keyColumn' => 'id',
+            'labelColumn' => 'name',
+          ]
         ],
         'is_province_abbreviated' => [
           'name' => 'is_province_abbreviated',
index 66e0cce0b88931c94ff11d268ffcf56715a0beb3..98c212ba29c3475bc1feb44754e04093b0d909d1 100644 (file)
@@ -201,10 +201,14 @@ class CRM_Core_PseudoConstant {
   public static function get($daoName, $fieldName, $params = array(), $context = NULL) {
     CRM_Core_DAO::buildOptionsContext($context);
     $flip = !empty($params['flip']);
+    // Historically this was 'false' but according to the notes in
+    // CRM_Core_DAO::buildOptionsContext it should be context dependent.
+    // timidly changing for 'search' only to fix world_region in search options.
+    $localizeDefault = in_array($context, ['search']) ? TRUE : FALSE;
     // Merge params with defaults
     $params += array(
       'grouping' => FALSE,
-      'localize' => FALSE,
+      'localize' => $localizeDefault,
       'onlyActive' => ($context == 'validate' || $context == 'get') ? FALSE : TRUE,
       'fresh' => FALSE,
       'context' => $context,
@@ -378,11 +382,8 @@ class CRM_Core_PseudoConstant {
           // Localize results
           if (!empty($params['localize']) || $pseudoconstant['table'] == 'civicrm_country' || $pseudoconstant['table'] == 'civicrm_state_province') {
             $I18nParams = array();
-            if ($pseudoconstant['table'] == 'civicrm_country') {
-              $I18nParams['context'] = 'country';
-            }
-            if ($pseudoconstant['table'] == 'civicrm_state_province') {
-              $I18nParams['context'] = 'province';
+            if (isset($fieldSpec['localize_context'])) {
+              $I18nParams['context'] = $fieldSpec['localize_context'];
             }
             $i18n = CRM_Core_I18n::singleton();
             $i18n->localizeArray($output, $I18nParams);
index 878b446df82b06c677a9b163a4c53b51a041a6af..c67aa09b0053f73da2c370d6e72e6885d6bb1f42 100644 (file)
       <keyColumn>id</keyColumn>
       <labelColumn>name</labelColumn>
     </pseudoconstant>
+    <localize_context>province</localize_context>
     <html>
       <type>ChainSelect</type>
     </html>
       <labelColumn>name</labelColumn>
       <nameColumn>iso_code</nameColumn>
     </pseudoconstant>
+    <localize_context>country</localize_context>
     <html>
       <type>Select</type>
     </html>
index bdfac28f1180775ea52a3656cc96e07aa9d504f0..e01d95511e8a3172ad7f29d4cc87232d2f4d785c 100644 (file)
     <required>true</required>
     <comment>Foreign key to civicrm_worldregion.id.</comment>
     <add>1.8</add>
+    <localize_context>country</localize_context>
+    <pseudoconstant>
+      <table>civicrm_worldregion</table>
+      <keyColumn>id</keyColumn>
+      <labelColumn>name</labelColumn>
+    </pseudoconstant>
   </field>
   <foreignKey>
     <name>region_id</name>
index 488ec34efddbc38ded15a7955a0683eda955abb7..82172516081b85bf195e50d90a24841cefa1dd73 100644 (file)
@@ -138,6 +138,7 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
   'entity' => '{$table.entity}',
   'bao' => '{$table.bao}',
   'localizable' => {if $field.localizable}1{else}0{/if},
+  {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if}
 
 {if $field.FKClassName}
                       'FKClassName' => '{$field.FKClassName}',