From 6dabf45983174141b25be3edbd795fd053db3d58 Mon Sep 17 00:00:00 2001 From: Mathieu Lutfy Date: Tue, 6 Aug 2019 10:40:25 -0400 Subject: [PATCH] Translation 'ts' usage fixes. --- CRM/Admin/Form/Options.php | 2 +- CRM/Admin/Form/Preferences/Contribute.php | 18 +++++++-------- CRM/Admin/Form/SettingTrait.php | 19 +++++++-------- CRM/Batch/Form/Entry.php | 3 ++- CRM/Contribute/BAO/Contribution.php | 2 +- .../FutureContributionPageException.php | 2 +- .../InactiveContributionPageException.php | 2 +- .../PastContributionPageException.php | 2 +- CRM/Contribute/Form/AbstractEditPayment.php | 4 ++-- CRM/Contribute/Form/Contribution/Main.php | 5 ++-- CRM/Contribute/Form/ContributionBase.php | 6 ++--- CRM/Event/Form/SelfSvcTransfer.php | 6 ++--- .../ParticipantListing/NameStatusAndDate.php | 5 +--- CRM/Financial/BAO/FinancialType.php | 23 +++++++++++-------- CRM/Utils/Mail/Incoming.php | 4 ++-- CRM/Utils/System/Backdrop.php | 2 +- .../CRM/Financial/BAO/FinancialTypeTest.php | 16 ++++++++----- 17 files changed, 64 insertions(+), 57 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index 3e8dd6a65a..824db5857e 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -400,7 +400,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE); if ($validate === FALSE) { CRM_Core_Session::setStatus( - ts('Data Type of the value field for this option value does not match ' . $dataType), + ts('Data Type of the value field for this option value does not match %1.', [1 => $dataType]), ts('Value field Data Type mismatch')); } } diff --git a/CRM/Admin/Form/Preferences/Contribute.php b/CRM/Admin/Form/Preferences/Contribute.php index 2367796184..6fc5e1dc17 100644 --- a/CRM/Admin/Form/Preferences/Contribute.php +++ b/CRM/Admin/Form/Preferences/Contribute.php @@ -116,15 +116,15 @@ class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { 'title' => ts('Tax Display Settings'), 'weight' => 8, 'option_values' => [ - 'Do_not_show' => ts('Do not show breakdown, only show total -i.e ' . - CRM_Core_BAO_Country::defaultCurrencySymbol() . '120.00'), - 'Inclusive' => ts('Show [tax term] inclusive price - i.e. ' . - CRM_Core_BAO_Country::defaultCurrencySymbol() . - '120.00 (includes [tax term] of ' . - CRM_Core_BAO_Country::defaultCurrencySymbol() . '20.00)'), - 'Exclusive' => ts('Show [tax term] exclusive price - i.e. ' . - CRM_Core_BAO_Country::defaultCurrencySymbol() . '100.00 + ' . - CRM_Core_BAO_Country::defaultCurrencySymbol() . '20.00 [tax term]'), + 'Do_not_show' => ts('Do not show breakdown, only show total - i.e %1', [ + 1 => CRM_Utils_Money::format(120), + ]), + 'Inclusive' => ts('Show [tax term] inclusive price - i.e. %1', [ + 1 => ts('%1 (includes [tax term] of %2)', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]), + ]), + 'Exclusive' => ts('Show [tax term] exclusive price - i.e. %1', [ + 1 => ts('%1 + %2 [tax term]', [1 => CRM_Utils_Money::format(120), 2 => CRM_Utils_Money::format(20)]), + ]), ], ], ]; diff --git a/CRM/Admin/Form/SettingTrait.php b/CRM/Admin/Form/SettingTrait.php index 672aa0d175..1642b79ddf 100644 --- a/CRM/Admin/Form/SettingTrait.php +++ b/CRM/Admin/Form/SettingTrait.php @@ -196,13 +196,13 @@ trait CRM_Admin_Form_SettingTrait { $this->$add( $props['html_type'], $setting, - ts($props['title']), + $props['title'], ($options !== NULL) ? $options : CRM_Utils_Array::value('html_attributes', $props, []), ($options !== NULL) ? CRM_Utils_Array::value('html_attributes', $props, []) : NULL ); } elseif ($add == 'addSelect') { - $this->addElement('select', $setting, ts($props['title']), $options, CRM_Utils_Array::value('html_attributes', $props)); + $this->addElement('select', $setting, $props['title'], $options, CRM_Utils_Array::value('html_attributes', $props)); } elseif ($add == 'addCheckBox') { $this->addCheckBox($setting, '', $options, NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, ['  ']); @@ -224,23 +224,23 @@ trait CRM_Admin_Form_SettingTrait { } elseif ($add == 'addChainSelect') { $this->addChainSelect($setting, [ - 'label' => ts($props['title']), + 'label' => $props['title'], ]); } elseif ($add == 'addMonthDay') { - $this->add('date', $setting, ts($props['title']), CRM_Core_SelectValues::date(NULL, 'M d')); + $this->add('date', $setting, $props['title'], CRM_Core_SelectValues::date(NULL, 'M d')); } elseif ($add === 'addEntityRef') { - $this->$add($setting, ts($props['title']), $props['entity_reference_options']); + $this->$add($setting, $props['title'], $props['entity_reference_options']); } elseif ($add === 'addYesNo' && ($props['type'] === 'Boolean')) { - $this->addRadio($setting, ts($props['title']), [1 => 'Yes', 0 => 'No'], NULL, '  '); + $this->addRadio($setting, $props['title'], [1 => 'Yes', 0 => 'No'], NULL, '  '); } elseif ($add === 'add') { - $this->add($props['html_type'], $setting, ts($props['title']), $options); + $this->add($props['html_type'], $setting, $props['title'], $options); } else { - $this->$add($setting, ts($props['title']), $options); + $this->$add($setting, $props['title'], $options); } // Migrate to using an array as easier in smart... $description = CRM_Utils_Array::value('description', $props); @@ -281,7 +281,8 @@ trait CRM_Admin_Form_SettingTrait { // not made this change. $htmlType = $spec['html_type']; if ($htmlType !== strtolower($htmlType)) { - CRM_Core_Error::deprecatedFunctionWarning(ts('Settings fields html_type should be lower case - see https://docs.civicrm.org/dev/en/latest/framework/setting/ - this needs to be fixed for ' . $spec['name'])); + // Avoiding 'ts' for obscure strings. + CRM_Core_Error::deprecatedFunctionWarning('Settings fields html_type should be lower case - see https://docs.civicrm.org/dev/en/latest/framework/setting/ - this needs to be fixed for ' . $spec['name']); $htmlType = strtolower($spec['html_type']); } $mapping = [ diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index d710f550b4..038f320944 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -264,7 +264,8 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { // set an offset to account for other vars we are not counting $offset = 50; if ((count($this->_elementIndex) + $offset) > ini_get("max_input_vars")) { - CRM_Core_Error::fatal(ts('Batch size is too large. Increase value of php.ini setting "max_input_vars" (current val = ' . ini_get("max_input_vars") . ')')); + // Avoiding 'ts' for obscure messages. + CRM_Core_Error::fatal('Batch size is too large. Increase value of php.ini setting "max_input_vars" (current val = ' . ini_get("max_input_vars") . ')'); } $this->assign('fields', $this->_fields); diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 24e1d8ea11..99a54446f4 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -110,7 +110,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params)); $duplicates = []; if (self::checkDuplicate($params, $duplicates, $contributionID)) { - $message = ts("Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: " . implode(', ', $duplicates)); + $message = ts("Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: %1", [1 => implode(', ', $duplicates)]); throw new CRM_Core_Exception($message); } diff --git a/CRM/Contribute/Exception/FutureContributionPageException.php b/CRM/Contribute/Exception/FutureContributionPageException.php index 5deeb178f4..d742713c08 100644 --- a/CRM/Contribute/Exception/FutureContributionPageException.php +++ b/CRM/Contribute/Exception/FutureContributionPageException.php @@ -8,7 +8,7 @@ class CRM_Contribute_Exception_FutureContributionPageException extends Exception * @param int $id */ public function __construct($message, $id) { - parent::__construct(ts($message)); + parent::__construct($message); $this->id = $id; CRM_Core_Error::debug_log_message('Access to contribution page with start date in future attempted - page number ' . $id); } diff --git a/CRM/Contribute/Exception/InactiveContributionPageException.php b/CRM/Contribute/Exception/InactiveContributionPageException.php index 5c8b82e65f..828a5c5798 100644 --- a/CRM/Contribute/Exception/InactiveContributionPageException.php +++ b/CRM/Contribute/Exception/InactiveContributionPageException.php @@ -14,7 +14,7 @@ class CRM_Contribute_Exception_InactiveContributionPageException extends Excepti * @param int $id */ public function __construct($message, $id) { - parent::__construct(ts($message)); + parent::__construct($message); $this->id = $id; CRM_Core_Error::debug_log_message('inactive contribution page access attempted - page number ' . $id); } diff --git a/CRM/Contribute/Exception/PastContributionPageException.php b/CRM/Contribute/Exception/PastContributionPageException.php index fc7c8b3182..71c825a7ab 100644 --- a/CRM/Contribute/Exception/PastContributionPageException.php +++ b/CRM/Contribute/Exception/PastContributionPageException.php @@ -8,7 +8,7 @@ class CRM_Contribute_Exception_PastContributionPageException extends Exception { * @param int $id */ public function __construct($message, $id) { - parent::__construct(ts($message)); + parent::__construct($message); $this->id = $id; CRM_Core_Error::debug_log_message('Access to contribution page with past end date attempted - page number ' . $id); } diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 38aea6074b..aafbf0a423 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -391,9 +391,9 @@ WHERE contribution_id = {$id} // for some reason there was a need to filter here per commit history - but this indicates a problem // somewhere else. if ($processor['is_test'] == ($this->_mode == 'test')) { - $this->_processors[$id] = ts($processor['name']); + $this->_processors[$id] = $processor['name']; if (!empty($processor['description'])) { - $this->_processors[$id] .= ' : ' . ts($processor['description']); + $this->_processors[$id] .= ' : ' . $processor['description']; } if ($processor['is_recur']) { $this->_recurPaymentProcessors[$id] = $this->_processors[$id]; diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 7738e66017..44d9ffecf1 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -716,14 +716,13 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $is_test ); - $errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.'; foreach ($self->_values['fee'] as $fieldKey => $fieldValue) { if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array::value('price_' . $fieldKey, $fields)) { if (!is_array($fields['price_' . $fieldKey]) && isset($fieldValue['options'][$fields['price_' . $fieldKey]])) { if (array_key_exists('membership_type_id', $fieldValue['options'][$fields['price_' . $fieldKey]]) && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships) ) { - $errors['price_' . $fieldKey] = ts($errorText, [1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])]); + $errors['price_' . $fieldKey] = ts('Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.', [1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])]); } } else { @@ -732,7 +731,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu if (array_key_exists('membership_type_id', $fieldValue['options'][$key]) && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships) ) { - $errors['price_' . $fieldKey] = ts($errorText, [1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$key]['membership_type_id'])]); + $errors['price_' . $fieldKey] = ts('Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.', [1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$key]['membership_type_id'])]); } } } diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 1cd24557cf..0399436fd8 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -323,12 +323,12 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $this->_values)); $now = date('YmdHis'); if ($endDate && $endDate < $now) { - throw new CRM_Contribute_Exception_PastContributionPageException(ts('The page you requested has past its end date on ' . CRM_Utils_Date::customFormat($endDate)), $this->_id); + throw new CRM_Contribute_Exception_PastContributionPageException(ts('The page you requested has past its end date on %1', [1 => CRM_Utils_Date::customFormat($endDate)]), $this->_id); } $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('start_date', $this->_values)); if ($startDate && $startDate > $now) { - throw new CRM_Contribute_Exception_FutureContributionPageException(ts('The page you requested will be active from ' . CRM_Utils_Date::customFormat($startDate)), $this->_id); + throw new CRM_Contribute_Exception_FutureContributionPageException(ts('The page you requested will be active from %1', [1 => CRM_Utils_Date::customFormat($startDate)]), $this->_id); } $this->assignBillingType(); @@ -945,7 +945,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { } } - $form->assign('fieldSetTitle', ts(CRM_Core_BAO_UFGroup::getTitle($form->_values['onbehalf_profile_id']))); + $form->assign('fieldSetTitle', CRM_Core_BAO_UFGroup::getTitle($form->_values['onbehalf_profile_id'])); if (CRM_Utils_Array::value('is_for_organization', $form->_values)) { if ($form->_values['is_for_organization'] == 2) { diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index a0e629e0aa..6127eaee0c 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -218,9 +218,9 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { } // for front-end user show and use the basic three fields used to create a contact else { - $this->add('text', 'email', ts('To Email'), ts($this->_contact_email), TRUE); - $this->add('text', 'last_name', ts('To Last Name'), ts($this->_to_contact_last_name), TRUE); - $this->add('text', 'first_name', ts('To First Name'), ts($this->_to_contact_first_name), TRUE); + $this->add('text', 'email', ts('To Email'), $this->_contact_email, TRUE); + $this->add('text', 'last_name', ts('To Last Name'), $this->_to_contact_last_name, TRUE); + $this->add('text', 'first_name', ts('To First Name'), $this->_to_contact_first_name, TRUE); } $this->addButtons([ diff --git a/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php b/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php index c2bf4eb3e2..e7b81bc3b0 100644 --- a/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php +++ b/CRM/Event/Page/ParticipantListing/NameStatusAndDate.php @@ -100,12 +100,9 @@ LIMIT $offset, $rowCount"; $rows = []; $object = CRM_Core_DAO::executeQuery($query, $params); - $statusLookup = CRM_Event_PseudoConstant::participantStatus(); + $statusLookup = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); while ($object->fetch()) { $status = CRM_Utils_Array::value($object->status_id, $statusLookup); - if ($status) { - $status = ts($status); - } $row = [ 'id' => $object->contact_id, 'participantID' => $object->participant_id, diff --git a/CRM/Financial/BAO/FinancialType.php b/CRM/Financial/BAO/FinancialType.php index 1d49d61931..b9154b1d6d 100644 --- a/CRM/Financial/BAO/FinancialType.php +++ b/CRM/Financial/BAO/FinancialType.php @@ -153,7 +153,7 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType { } } if (!empty($tables)) { - $message = ts('The following tables have an entry for this financial type: %1', ['%1' => implode(', ', $tables)]); + $message = ts('The following tables have an entry for this financial type: %1', [1 => implode(', ', $tables)]); $errors = []; $errors['is_error'] = 1; @@ -217,27 +217,32 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType { return FALSE; } $financialTypes = CRM_Contribute_PseudoConstant::financialType(); - $prefix = ts('CiviCRM') . ': '; - $actions = ['add', 'view', 'edit', 'delete']; + $actions = [ + 'add' => ts('add'), + 'view' => ts('view'), + 'edit' => ts('edit'), + 'delete' => ts('delete'), + ]; + foreach ($financialTypes as $id => $type) { - foreach ($actions as $action) { + foreach ($actions as $action => $action_ts) { if ($descriptions) { $permissions[$action . ' contributions of type ' . $type] = [ - $prefix . ts($action . ' contributions of type ') . $type, - ts(ucfirst($action) . ' contributions of type ') . $type, + ts("CiviCRM: %1 contributions of type %2", [1 => $action_ts, 2 => $type]), + ts('%1 contributions of type %2', [1 => $action_ts, 2 => $type]), ]; } else { - $permissions[$action . ' contributions of type ' . $type] = $prefix . ts($action . ' contributions of type ') . $type; + $permissions[$action . ' contributions of type ' . $type] = ts("CiviCRM: %1 contributions of type %2", [1 => $action_ts, 2 => $type]); } } } if (!$descriptions) { - $permissions['administer CiviCRM Financial Types'] = $prefix . ts('administer CiviCRM Financial Types'); + $permissions['administer CiviCRM Financial Types'] = ts('CiviCRM: administer CiviCRM Financial Types'); } else { $permissions['administer CiviCRM Financial Types'] = [ - $prefix . ts('administer CiviCRM Financial Types'), + ts('CiviCRM: administer CiviCRM Financial Types'), ts('Administer access to Financial Types'), ]; } diff --git a/CRM/Utils/Mail/Incoming.php b/CRM/Utils/Mail/Incoming.php index eed6ec8075..f2bd36d989 100644 --- a/CRM/Utils/Mail/Incoming.php +++ b/CRM/Utils/Mail/Incoming.php @@ -254,8 +254,8 @@ class CRM_Utils_Mail_Incoming { * @return string */ public function formatUnrecognisedPart($part) { - CRM_Core_Error::debug_log_message(ts('CRM_Utils_Mail_Incoming: Unable to handle message part of type "%1".', ['%1' => get_class($part)])); - return ts('Unrecognised message part of type "%1".', ['%1' => get_class($part)]); + CRM_Core_Error::debug_log_message(ts('CRM_Utils_Mail_Incoming: Unable to handle message part of type "%1".', [1 => get_class($part)])); + return ts('Unrecognised message part of type "%1".', [1 => get_class($part)]); } /** diff --git a/CRM/Utils/System/Backdrop.php b/CRM/Utils/System/Backdrop.php index 55804ddaac..eb34b8a2b7 100644 --- a/CRM/Utils/System/Backdrop.php +++ b/CRM/Utils/System/Backdrop.php @@ -133,7 +133,7 @@ class CRM_Utils_System_Backdrop extends CRM_Utils_System_DrupalBase { if (!empty($params['mail'])) { if (!valid_email_address($params['mail'])) { - $errors[$emailName] = ts('The e-mail address %1 is not valid.', ['%1' => $params['mail']]); + $errors[$emailName] = ts('The e-mail address %1 is not valid.', [1 => $params['mail']]); } else { $uid = db_query("SELECT uid FROM {users} WHERE mail = :mail", [':mail' => $params['mail']])->fetchField(); diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php index c438c9d5bb..c39a5cd088 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php @@ -208,18 +208,22 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { $this->setACL(); CRM_Financial_BAO_FinancialType::permissionedFinancialTypes($permissions, TRUE); $financialTypes = CRM_Contribute_PseudoConstant::financialType(); - $prefix = ts('CiviCRM') . ': '; - $actions = ['add', 'view', 'edit', 'delete']; + $actions = [ + 'add' => ts('add'), + 'view' => ts('view'), + 'edit' => ts('edit'), + 'delete' => ts('delete'), + ]; foreach ($financialTypes as $id => $type) { - foreach ($actions as $action) { + foreach ($actions as $action => $action_ts) { $checkPerms[$action . ' contributions of type ' . $type] = [ - $prefix . ts($action . ' contributions of type ') . $type, - ts(ucfirst($action) . ' contributions of type ') . $type, + ts("CiviCRM: %1 contributions of type %2", [1 => $action_ts, 2 => $type]), + ts('%1 contributions of type %2', [1 => $action_ts, 2 => $type]), ]; } } $checkPerms['administer CiviCRM Financial Types'] = [ - $prefix . ts('administer CiviCRM Financial Types'), + ts('CiviCRM: administer CiviCRM Financial Types'), ts('Administer access to Financial Types'), ]; $this->assertEquals($permissions, $checkPerms, 'Verify that permissions for each financial type have been added'); -- 2.25.1