Skip to content

Commit

Permalink
CPS-432: Create new function to translate variables
Browse files Browse the repository at this point in the history
  • Loading branch information
deb1990 committed Jul 30, 2021
1 parent f4b101f commit cbb1bb2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CRM_Civicase_Hook_Helper_CaseTypeCategory as CaseTypeCategoryHelper;

/**
* Class CaseCategoryFormLabelTranslationForChangeCase.
*/
Expand Down Expand Up @@ -57,7 +59,7 @@ private function translateFormLabels(CRM_Core_Form $form) {
* For Elements array.
*/
private function translateLabel($element) {
$label = $element->getLabel();
$label = CaseTypeCategoryHelper::translate($element->getLabel());
$element->setLabel($label);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private function translateFormLabels(CRM_Core_Form $form) {
*/
private function translateLabel(array $elements) {
foreach ($elements as $element) {
$label = $element->getLabel();
$label = CaseTypeCategoryHelper::translate($element->getLabel());
$element->setLabel($label);
}
}
Expand Down
20 changes: 20 additions & 0 deletions CRM/Civicase/Hook/Helper/CaseTypeCategory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use CRM_Civicase_ExtensionUtil as E;
use CRM_Civicase_Helper_CaseCategory as CaseCategoryHelper;
use CRM_Civicase_Service_CaseCategorySetting as CaseCategorySetting;

Expand Down Expand Up @@ -122,4 +123,23 @@ public static function getNewCaseCategoryWebformUrl($caseCategoryName, CaseCateg
return $allowCaseCategoryWebform ? Civi::settings()->get($caseCategoryWebformUrl) : NULL;
}

/**
* This is wrapper for "E::ts" function.
*
* CiviCRM does not recomment 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.
*
* @param string $value
* Value to be translated.
*
* @return string
* Translated value.
*/
public static function translate($value) {
return E::ts($value);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use CRM_Civicase_Helper_CaseCategory as CaseCategoryHelper;
use CRM_Civicase_Hook_Helper_CaseTypeCategory as CaseTypeCategoryHelper;

/**
* Class CaseCategoryWordReplacementsForChangeCase.
Expand Down Expand Up @@ -50,7 +51,7 @@ private function addWordReplacements(CRM_Core_Form $form) {
* Form Object.
*/
private function setPageTitle(CRM_Core_Form $form) {
$pageTitle = $form->get_template_vars('activityTypeName');
$pageTitle = CaseTypeCategoryHelper::translate($form->get_template_vars('activityTypeName'));
$displayName = $this->getContactDisplayName($form);
if ($displayName) {
CRM_Utils_System::setTitle($displayName . ' - ' . $pageTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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($pageTitle);
CRM_Utils_System::setTitle(CaseTypeCategoryHelper::translate($pageTitle));
CaseCategoryHelper::updateBreadcrumbs($caseCategoryId);
}

Expand Down
6 changes: 3 additions & 3 deletions CRM/Civicase/Hook/Tokens/AddContactTokens.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use CRM_Civicase_ExtensionUtil as E;
use CRM_Civicase_Hook_Helper_CaseTypeCategory as CaseTypeCategoryHelper;

/**
* Add current user tokens.
Expand Down Expand Up @@ -52,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] =
E::ts('Current User ') . ucwords(str_replace("_", " ", $field));
CaseTypeCategoryHelper::translate('Current User ' . ucwords(str_replace("_", " ", $field)));
}
foreach ($this->contactCustomFieldsService->get() as $key => $field) {
$tokens[self::TOKEN_KEY]['current_user.contact_' . $key] =
E::ts('Current User ') . ucwords(str_replace("_", " ", $field));
CaseTypeCategoryHelper::translate('Current User ' . ucwords(str_replace("_", " ", $field)));
}
}

Expand Down

0 comments on commit cbb1bb2

Please sign in to comment.