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

CPS-432: Fix ts function usage #796

Merged
merged 4 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 87 additions & 85 deletions CRM/Civicase/Form/Report/ColumnDefinitionTrait.php

Large diffs are not rendered by default.

446 changes: 223 additions & 223 deletions CRM/Civicase/Form/Report/ExtendedReport.php

Large diffs are not rendered by default.

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 = ts($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 = ts($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);
}

}
7 changes: 4 additions & 3 deletions CRM/Civicase/Hook/Permissions/CaseCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use CRM_Civicase_Helper_CaseCategory as CaseCategoryHelper;

/**
* Class CRM_Civicase_Hook_Permissions_CaseCategory.
* Case Category Permissions hook.
*/
class CRM_Civicase_Hook_Permissions_CaseCategory {

Expand All @@ -27,6 +27,7 @@ class CRM_Civicase_Hook_Permissions_CaseCategory {
* CRM_Civicase_Hook_Permissions_CaseCategory constructor.
*
* @param array $permissions
* Permissions.
*/
public function __construct(array &$permissions) {
$this->permissions = &$permissions;
Expand Down Expand Up @@ -55,7 +56,7 @@ private function addCivicaseDefaultPermissions() {
$caseCategoryPermissions = $this->permissionService->get();
$this->permissions[$caseCategoryPermissions['BASIC_CASE_CATEGORY_INFO']['name']] = [
$caseCategoryPermissions['BASIC_CASE_CATEGORY_INFO']['label'],
ts($caseCategoryPermissions['BASIC_CASE_CATEGORY_INFO']['description']),
$caseCategoryPermissions['BASIC_CASE_CATEGORY_INFO']['description'],
];
}

Expand All @@ -76,7 +77,7 @@ private function addCaseCategoryPermissions() {
foreach ($caseCategoryPermissions as $caseCategoryPermission) {
$this->permissions[$caseCategoryPermission['name']] = [
$caseCategoryPermission['label'],
ts($caseCategoryPermission['description']),
$caseCategoryPermission['description'],
];
}
}
Expand Down
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 = ts($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(ts($pageTitle));
CRM_Utils_System::setTitle(CaseTypeCategoryHelper::translate($pageTitle));
CaseCategoryHelper::updateBreadcrumbs($caseCategoryId);
}

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

use CRM_Civicase_Hook_Helper_CaseTypeCategory as CaseTypeCategoryHelper;

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

Expand Down
25 changes: 14 additions & 11 deletions CRM/Civicase/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use CRM_Civicase_Service_CaseCategoryInstance as CaseCategoryInstance;
use CRM_Civicase_Helper_CaseUrl as CaseUrlHelper;
use CRM_Civicase_Setup_AddSingularLabels as AddSingularLabels;
use CRM_Civicase_ExtensionUtil as E;

/**
* Collection of upgrade steps.
Expand Down Expand Up @@ -152,7 +153,7 @@ public function install() {
*/
private function createManageCasesMenuItem() {
$this->addNav([
'label' => ts('Manage Cases', ['domain' => 'uk.co.compucorp.civicase']),
'label' => E::ts('Manage Cases'),
'name' => 'Manage Cases',
'url' => CaseUrlHelper::getUrlByRouteType('all'),
'permission' => 'access my cases and activities,access all cases and activities',
Expand Down Expand Up @@ -301,47 +302,47 @@ private function addAllOptionValues() {
// Create activity types.
$this->addOptionValue([
'option_group_id' => 'activity_type',
'label' => ts('Alert'),
'label' => E::ts('Alert'),
'name' => 'Alert',
'grouping' => 'alert',
'is_reserved' => 0,
'description' => ts('Alerts to display in cases'),
'description' => E::ts('Alerts to display in cases'),
'component_id' => 'CiviCase',
'icon' => 'fa-exclamation',
]);
$this->addOptionValue([
'option_group_id' => 'activity_type',
'label' => ts('File Upload'),
'label' => E::ts('File Upload'),
'name' => 'File Upload',
'grouping' => 'file',
'is_reserved' => 0,
'description' => ts('Add files to a case'),
'description' => E::ts('Add files to a case'),
'component_id' => 'CiviCase',
'icon' => 'fa-file',
]);
$this->addOptionValue([
'option_group_id' => 'activity_type',
'label' => ts('Remove Client From Case'),
'label' => E::ts('Remove Client From Case'),
'name' => 'Remove Client From Case',
'grouping' => 'system',
'is_reserved' => 0,
'description' => ts('Client removed from multi-client case'),
'description' => E::ts('Client removed from multi-client case'),
'component_id' => 'CiviCase',
'icon' => 'fa-user-times',
]);

// Create activity statuses.
$this->addOptionValue([
'option_group_id' => 'activity_status',
'label' => ts('Unread'),
'label' => E::ts('Unread'),
'name' => 'Unread',
'grouping' => 'communication',
'is_reserved' => 0,
'color' => '#d9534f',
]);
$this->addOptionValue([
'option_group_id' => 'activity_status',
'label' => ts('Draft'),
'label' => E::ts('Draft'),
'name' => 'Draft',
'grouping' => 'communication',
'is_reserved' => 0,
Expand Down Expand Up @@ -500,8 +501,10 @@ public function enqueuePendingRevisions(CRM_Queue_Queue $queue) {
if ($revisionNum <= $currentRevisionNum) {
continue;
}
$tsParams = [1 => $this->extensionName, 2 => $revisionNum];
$title = ts('Upgrade %1 to revision %2', $tsParams);
$title = E::ts('Upgrade %1 to revision %2', [
1 => $this->extensionName,
2 => $revisionNum,
]);
$upgradeTask = new CRM_Queue_Task(
[get_class($this), 'runStepUpgrade'],
[(new $revisionClass())],
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ Link to extension: https://github.com/civicrm/org.civicrm.casetokens
* Case status now has a ‘Status class’ field to show cases which are incomplete, completed, or cancelled.

# Technical Requirements
* CiviCRM: version >= v5.8, preferably the latest version.
* CiviCRM: CiviCase is designed and tested with a [patched version of CiviCRM v5.35.2](https://github.com/compucorp/civicrm-core/releases/download/5.35.2%2Bpatch.f58e72/civicrm-5.35.2+patch.f58e72.tar.gz) and may have unforeseen issues with newer versions of CiviCRM and hence we would recommend only using it with that version of CiviCRM. Compucorp normally undertakes to update these extensions shortly after a new CiviCRM security release.
* [Shoreditch](https://github.com/civicrm/org.civicrm.shoreditch): version >= v0.1-alpha32, preferably the latest version.
* [Usermenu](https://github.com/compucorp/uk.co.compucorp.usermenu).
* (Recommended) Migrate from embedded activity revisions to full system logging ([CRM-21051](https://issues.civicrm.org/jira/browse/CRM-21051))

# Installation (git/cli)
Expand All @@ -137,6 +138,6 @@ To install the extension on an existing CiviCRM site:
mkdir sites/all/modules/civicrm/ext
cd sites/all/modules/civicrm/ext
git clone https://github.com/civicrm/org.civicrm.shoreditch shoreditch
git clone https://github.com/compucorp/uk.co.compucorp.usermenu usermenu
git clone https://github.com/compucorp/uk.co.compucorp.civicase civicase
cv en shoreditch civicase

cv en shoreditch usermenu civicase
14 changes: 14 additions & 0 deletions gulp-tasks/generate-translations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file
* Exports Gulp task to generate translation files.
*/

'use strict';

var execSync = require('child_process').execSync;

module.exports = function (done) {
execSync('civistrings -o "l10n/civicase.pot" ./ang/ ./api/ ./Civi/ ./CRM/ ./settings/');

done();
};
3 changes: 3 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var sassTask = require('./gulp-tasks/sass.js');
var sassSyncTask = require('./gulp-tasks/sass-sync.js');
var testTask = require('./gulp-tasks/karma-unit-test.js');
var watchTask = require('./gulp-tasks/watch.js');
var generateTranslationsTask = require('./gulp-tasks/generate-translations.js');

/**
* Updates and sync the scssRoot paths
Expand All @@ -44,3 +45,5 @@ gulp.task('watch', watchTask);
* Runs sass and test task
*/
gulp.task('default', gulp.series('sass', 'test'));

gulp.task('generate-translations', generateTranslationsTask);
Loading