From 65c86f7db8c97577fcb3a8c9d2a59f6d1e4ad881 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 3 Dec 2018 14:44:13 +1300 Subject: [PATCH] Define gettext translation for world_region --- CRM/Core/BAO/Address.php | 2 +- CRM/Core/CodeGen/Specification.php | 4 +++- CRM/Core/DAO/Address.php | 4 +++- CRM/Core/DAO/Country.php | 8 +++++++- CRM/Core/PseudoConstant.php | 13 +++++++------ xml/schema/Core/Address.xml | 2 ++ xml/schema/Core/Country.xml | 6 ++++++ xml/templates/dao.tpl | 1 + 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 338712adfb..a49737ad30 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -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); } diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index 6d15ae5e0e..faaaacce7d 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -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 diff --git a/CRM/Core/DAO/Address.php b/CRM/Core/DAO/Address.php index 98677499ef..0f7e94aa5f 100644 --- a/CRM/Core/DAO/Address.php +++ b/CRM/Core/DAO/Address.php @@ -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', diff --git a/CRM/Core/DAO/Country.php b/CRM/Core/DAO/Country.php index 2860eaf061..5f31cab89b 100644 --- a/CRM/Core/DAO/Country.php +++ b/CRM/Core/DAO/Country.php @@ -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', diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 66e0cce0b8..98c212ba29 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -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); diff --git a/xml/schema/Core/Address.xml b/xml/schema/Core/Address.xml index 878b446df8..c67aa09b00 100644 --- a/xml/schema/Core/Address.xml +++ b/xml/schema/Core/Address.xml @@ -284,6 +284,7 @@ id name + province ChainSelect @@ -350,6 +351,7 @@ name iso_code + country Select diff --git a/xml/schema/Core/Country.xml b/xml/schema/Core/Country.xml index bdfac28f11..e01d95511e 100644 --- a/xml/schema/Core/Country.xml +++ b/xml/schema/Core/Country.xml @@ -80,6 +80,12 @@ true Foreign key to civicrm_worldregion.id. 1.8 + country + + civicrm_worldregion
+ id + name +
region_id diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index 488ec34efd..8217251608 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -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}', -- 2.25.1