-
Notifications
You must be signed in to change notification settings - Fork 16
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
CPS-432: Fix ts function usage #796
Conversation
2cc2059
to
800095c
Compare
de1651f
to
2cd5055
Compare
@jamienovick @james-compucorp @tunbola This PR is in response to #580. I have fixed the the translation issues, but to to make civicase compatible with transifex, we need to make civicase |
@@ -57,7 +57,7 @@ private function translateFormLabels(CRM_Core_Form $form) { | |||
* For Elements array. | |||
*/ | |||
private function translateLabel($element) { | |||
$label = ts($element->getLabel()); | |||
$label = $element->getLabel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is used to change relevant form labels for the Change Case Type
, Change Case Status
and Link Cases
to the respective case category equivalent.
I know ts function should only be used with string values but in this case, existing functionality will be broken as this serves a purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, created a new function as discussed.
@@ -52,7 +52,7 @@ private function translateFormLabels(CRM_Core_Form $form) { | |||
*/ | |||
private function translateLabel(array $elements) { | |||
foreach ($elements as $element) { | |||
$label = ts($element->getLabel()); | |||
$label = $element->getLabel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Please check my comment on existing functionality being broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, created a new function as discussed.
@@ -50,7 +50,7 @@ private function addWordReplacements(CRM_Core_Form $form) { | |||
* Form Object. | |||
*/ | |||
private function setPageTitle(CRM_Core_Form $form) { | |||
$pageTitle = ts($form->get_template_vars('activityTypeName')); | |||
$pageTitle = $form->get_template_vars('activityTypeName'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that this also serves a purpose. Without the translation here. Existing functionality will be broken and page titles will not be translated for the respective case category.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, created a new function as discussed.
@@ -47,7 +47,7 @@ private function addWordReplacements(CRM_Core_Form $form, $caseCategoryId) { | |||
// We need to translate this manually as Civi does not the page title | |||
// through the ts function. | |||
$pageTitle = $form->get_template_vars('activityType'); | |||
CRM_Utils_System::setTitle(ts($pageTitle)); | |||
CRM_Utils_System::setTitle($pageTitle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the translation function here will also break existing functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, created a new function as discussed.
@@ -50,11 +52,11 @@ public function __construct( | |||
public function run(array &$tokens) { | |||
foreach ($this->contactFieldsService->get() as $field) { | |||
$tokens[self::TOKEN_KEY]['current_user.contact_' . $field] = | |||
ts('Current User ' . ucwords(str_replace("_", " ", $field))); | |||
E::ts('Current User ') . ucwords(str_replace("_", " ", $field)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also do
E::ts('Current User %1', array(
1 => ucwords(str_replace("_", " ", $field),
));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept it like it was before, and just applied the newly created function.
bf9591b
to
7b47a62
Compare
7b47a62
to
cbb1bb2
Compare
Overview
The PR implements proper usage of the
ts
or translation function.Technical Details
E::ts
instead ofts
.ts
function should only be used with string values, so applied the same.generate-translations
has been added, which will generate the translation file(.pot
).New function created for translation
Under
CRM_Civicase_Hook_Helper_CaseTypeCategory
class a new functiontranslate
has been created.This is wrapper for "E::ts" function.
CiviCRM does not recommend to use this to translate variables. But in CiviCase, we have used this function in few places with variables to achieve certain results. Hence this new function has been created, so that it can be only used in the places where it is absolutely necessary.
The Backstop Tests were run in https://github.com/compucorp/cases-product-suite-backstopjs/actions/runs/1081871388.