Skip to content

Commit

Permalink
Update translation template and fix incorrect use of ts()
Browse files Browse the repository at this point in the history
  • Loading branch information
jensschuppe committed Sep 24, 2024
1 parent 2834f80 commit fa30167
Show file tree
Hide file tree
Showing 5 changed files with 862 additions and 274 deletions.
21 changes: 12 additions & 9 deletions CRM/Twingle/BAO/TwingleProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,16 @@ public function add($mode = 'create') {
}
catch (\Civi\Core\Exception\DBQueryException $e) {
throw new ProductException(
E::ts('Could not find TwingleProduct in database: ' . $e->getMessage()),
E::ts('Could not find TwingleProduct in database: %1', [1 => $e->getMessage()]),
ShopException::ERROR_CODE_COULD_NOT_FIND_SHOP_IN_DB);
}

// Register pre-hook
$twingle_product_values = $this->getAttributes();
try {
\CRM_Utils_Hook::pre($mode, 'TwingleProduct', $this->id, $twingle_product_values);
} catch (\Exception $e) {
}
catch (\Exception $e) {
$tx->rollback();
throw $e;
}
Expand All @@ -481,14 +482,15 @@ public function add($mode = 'create') {
// Save object to database
try {
$this->save();
} catch (\Exception $e) {
}
catch (\Exception $e) {
$tx->rollback();
throw new ProductException(
E::ts('Could not save TwingleProduct to database: ' . $e->getMessage()),
E::ts('Could not save TwingleProduct to database: %1', [1 => $e->getMessage()]),
ProductException::ERROR_CODE_COULD_NOT_CREATE_PRODUCT);
}
$result = self::findById($this->id);
/* @var self $result */
/** @var self $result */
$this->load($result->getAttributes());

// Register post-hook
Expand Down Expand Up @@ -629,15 +631,15 @@ public function deletePriceField(): void {
}
catch (CRM_Core_Exception $e) {
throw new ProductException(
E::ts('An Error occurred while searching for the associated PriceFieldValue: ' . $e->getMessage()),
E::ts('An Error occurred while searching for the associated PriceFieldValue: %1', [1 => $e->getMessage()]),
ProductException::ERROR_CODE_PRICE_FIELD_VALUE_NOT_FOUND);
}
try {
civicrm_api3('PriceFieldValue', 'delete', ['id' => $result['id']]);
}
catch (CRM_Core_Exception $e) {
throw new ProductException(
E::ts('Could not delete associated PriceFieldValue: ' . $e->getMessage()),
E::ts('Could not delete associated PriceFieldValue: %1', [1 => $e->getMessage()]),
ProductException::ERROR_CODE_COULD_NOT_DELETE_PRICE_FIELD_VALUE);
}

Expand All @@ -661,13 +663,14 @@ public function deletePriceField(): void {
}
catch (CRM_Core_Exception $e) {
throw new ProductException(
E::ts('An Error occurred while searching for the associated PriceField: ' . $e->getMessage()),
E::ts('An Error occurred while searching for the associated PriceField: %1', [1 => $e->getMessage()]),
ProductException::ERROR_CODE_PRICE_FIELD_NOT_FOUND);
}
throw new ProductException(
E::ts('Could not delete associated PriceField: ' . $e->getMessage()),
E::ts('Could not delete associated PriceField: %1', [1 => $e->getMessage()]),
ProductException::ERROR_CODE_COULD_NOT_DELETE_PRICE_FIELD);
}
$this->price_field_id = NULL;
}

}
18 changes: 10 additions & 8 deletions CRM/Twingle/BAO/TwingleShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ public function add($mode = 'create') {
if ($dao->fetch()) {
$this->load($dao->toArray());
}
} catch (\Civi\Core\Exception\DBQueryException $e) {
}
catch (\Civi\Core\Exception\DBQueryException $e) {
throw new ShopException(
E::ts('Could not find TwingleShop in database: ' . $e->getMessage()),
E::ts('Could not find TwingleShop in database: %1', [1 => $e->getMessage()]),
ShopException::ERROR_CODE_COULD_NOT_FIND_SHOP_IN_DB);
}

Expand Down Expand Up @@ -191,7 +192,7 @@ function deleteByConstraint() {
catch (\CRM_Core_Exception $e) {
if ($e->getMessage() != 'Expected one PriceSet but found 0') {
throw new ShopException(
E::ts('Could not find associated PriceSet: ' . $e->getMessage()),
E::ts('Could not find associated PriceSet: %1', [1 => $e->getMessage()]),
ShopException::ERROR_CODE_PRICE_SET_NOT_FOUND);
}
else {
Expand All @@ -207,7 +208,7 @@ function deleteByConstraint() {
['id' => $this->price_set_id]);
} catch (\CRM_Core_Exception $e) {
throw new ShopException(
E::ts('Could not delete associated PriceSet: ' . $e->getMessage()),
E::ts('Could not delete associated PriceSet: %1', [1 => $e->getMessage()]),
ShopException::ERROR_CODE_COULD_NOT_DELETE_PRICE_SET);
}

Expand Down Expand Up @@ -451,9 +452,10 @@ function($project) {
public function deleteProducts() {
try {
$products = $this->getProducts();
} catch (\Civi\Core\Exception\DBQueryException $e) {
}
catch (\Civi\Core\Exception\DBQueryException $e) {
throw new ProductException(
E::ts('Could not retrieve associated products: ' . $e->getMessage()),
E::ts('Could not retrieve associated products: %1', [1 => $e->getMessage()]),
ProductException::ERROR_CODE_COULD_NOT_GET_PRODUCTS
);
}
Expand All @@ -464,8 +466,8 @@ public function deleteProducts() {
}
catch (ProductException $e) {
throw new ProductException(
E::ts('Could not delete associated products: ' . $e->getMessage()),
ProductException::ERROR_CODE_COULD_NOT_DELETE_PRICE_SET
E::ts('Could not delete associated products: %1', [1 => $e->getMessage()]),
ProductException::ERROR_CODE_COULD_NOT_DELETE_PRICE_SET,
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions CRM/Twingle/Form/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,7 @@ public function setDefaultValues() {
if (!isset($profile_data[$key]) && $required) {
CRM_Core_Session::setStatus(
E::ts(
'The required configuration option "%1" has no value.'
. ' Saving the profile might set this option to a possibly unwanted default value.',
'The required configuration option "%1" has no value. Saving the profile might set this option to a possibly unwanted default value.',
[1 => $metadata['label'] ?? $key]
),
E::ts('Error'),
Expand Down
2 changes: 1 addition & 1 deletion CRM/Twingle/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public static function createLineItems($values, $submission, $profile): array {
if (!empty($line_item['is_error'])) {
$line_item_name = $line_item_data['name'];
throw new CiviCRM_API3_Exception(
E::ts("Could not create line item for product '$line_item_name'"),
E::ts("Could not create line item for product '%1'", [1 => $line_item_name]),
'api_error'
);
}
Expand Down
Loading

0 comments on commit fa30167

Please sign in to comment.