Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make world_region translate on advanced search field #13212

Merged
merged 2 commits into from
Dec 4, 2018

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Fixes lack of translation for world region on advanced search screen

Before

screenshot 2018-12-03 13 48 46

After

screenshot 2018-12-03 14 32 38

Technical Details

Per digging in #13127 - the getLabel function is being called with localizable = 0 even though

CRM_Core_DAO::buildOptionsContext

clearly specifies that localisation is by context and

    $contexts = array(
      'get' => "get: all options are returned, even if they are disabled; labels are translated.",
      'create' => "create: options are filtered appropriately for the object being created/updated; labels are translated.",
      'search' => "search: searchable options are returned; labels are translated.",
      'validate' => "validate: all options are returned, even if they are disabled; machine names are used in place of labels.",
      'abbreviate' => "abbreviate: enabled options are returned; labels are replaced with abbreviations.",
      'match' => "match: enabled options are returned using machine names as keys; labels are translated.",
    );

The key line is here - the various buildOptions functions call this

In the case of world_region the translation is done by gettext - the reason this issue is less obvious apart from this field is that most fields rely on option value overrides.

The issue came up because digging here #13127 suggest that in some cases we fall back on gettext - seemingly in export we do this when locale-specific options are not defined too

Comments

Note that even after this search builder shows the untranslated fields - that would require ALSO changing for context 'get' which I left our of scope in this round

@mlutfy @mattwire @colemanw @samuelsov ....

@civibot
Copy link

civibot bot commented Dec 3, 2018

(Standard links)

@civibot civibot bot added the master label Dec 3, 2018
// Merge params with defaults
$params += array(
'grouping' => FALSE,
'localize' => FALSE,
'localize' => $localizeDefault,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton can we directly use:

$params += array(
...
'localize' => (in_array($context, ['search'])),
);

as $localizeDefault isn't used anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - but I kinda wanted to put a bunch of comments with it as this feels a little risky so doing it first gave me a space to do that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see, no problem. It's a wise choice to get some comment space over reduce-variable-assignment.

@@ -1349,7 +1349,7 @@ public static function buildOptions($fieldName, $context = NULL, $props = array(
case 'world_region':
case 'worldregion':
case 'worldregion_id':
return CRM_Core_PseudoConstant::worldRegion();
return CRM_Core_BAO_Country::buildOptions('region_id', $context);
Copy link
Member

@monishdeb monishdeb Dec 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and this will eventually call

CRM_Core_PseudoConstant::get('CRM_Core_BAO_Country', $fieldName, 'region_id',[], $context);

@eileenmcnaughton can you pass the $props parameter too? i.e.

        return CRM_Core_BAO_Country::buildOptions('region_id', $context, $props);

just in case :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks


if (isset($fieldXML->localize_context)) {
$field['localize_context'] = $fieldXML->localize_context;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

@monishdeb
Copy link
Member

I agree with the patch, however, there are two minor changes needed in the PR, so I am tagging merge-ready.

@monishdeb monishdeb added the merge ready PR will be merged after a few days if there are no objections label Dec 3, 2018
@monishdeb
Copy link
Member

Agree with the final patch. Tagging MoP

@monishdeb monishdeb added merge on pass and removed merge ready PR will be merged after a few days if there are no objections labels Dec 3, 2018
@eileenmcnaughton eileenmcnaughton force-pushed the export_wr branch 2 times, most recently from 673c89f to 37f0ce9 Compare December 3, 2018 10:19
@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

@eileenmcnaughton looks like test failures relate

All have the change of

-    'country' => 'country varchar(64)'
+    'country' => 'country varchar(16)'

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

Merging as per the tag

@seamuslee001 seamuslee001 merged commit 5270e28 into civicrm:master Dec 4, 2018
@seamuslee001 seamuslee001 deleted the export_wr branch December 4, 2018 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants