From b4d565400e368a260d74cf93b925ad6734af32cf Mon Sep 17 00:00:00 2001 From: Dominic Guhl <--global> Date: Sat, 26 Oct 2019 15:07:54 +0200 Subject: [PATCH] Issue 2695 Introduces localisation for API errors --- .../V1/Controllers/AttachmentController.php | 8 ++-- app/Api/V1/Controllers/BillController.php | 2 +- app/Api/V1/Controllers/BudgetController.php | 2 +- .../V1/Controllers/BudgetLimitController.php | 2 +- app/Api/V1/Controllers/CategoryController.php | 2 +- .../Controllers/ConfigurationController.php | 2 +- app/Api/V1/Controllers/CurrencyController.php | 6 +-- .../CurrencyExchangeRateController.php | 4 +- app/Api/V1/Controllers/LinkTypeController.php | 8 ++-- .../V1/Controllers/PiggyBankController.php | 2 +- .../V1/Controllers/RecurrenceController.php | 2 +- .../V1/Controllers/RuleGroupController.php | 2 +- .../Controllers/TransactionLinkController.php | 4 +- app/Api/V1/Controllers/UserController.php | 2 +- resources/lang/cs_CZ/api.php | 26 +++++++++++ resources/lang/de_DE/api.php | 26 +++++++++++ resources/lang/el_GR/api.php | 26 +++++++++++ resources/lang/en_US/api.php | 45 +++++++++++++++++++ resources/lang/es_ES/api.php | 26 +++++++++++ resources/lang/fr_FR/api.php | 26 +++++++++++ resources/lang/hu_HU/api.php | 26 +++++++++++ resources/lang/id_ID/api.php | 26 +++++++++++ resources/lang/it_IT/api.php | 26 +++++++++++ resources/lang/nb_NO/api.php | 26 +++++++++++ resources/lang/nl_NL/api.php | 26 +++++++++++ resources/lang/pl_PL/api.php | 26 +++++++++++ resources/lang/pt_BR/api.php | 26 +++++++++++ resources/lang/ro_RO/api.php | 26 +++++++++++ resources/lang/ru_RU/api.php | 26 +++++++++++ resources/lang/tr_TR/api.php | 26 +++++++++++ resources/lang/zh_CN/api.php | 26 +++++++++++ resources/lang/zh_TW/api.php | 26 +++++++++++ 32 files changed, 511 insertions(+), 24 deletions(-) create mode 100644 resources/lang/cs_CZ/api.php create mode 100644 resources/lang/de_DE/api.php create mode 100644 resources/lang/el_GR/api.php create mode 100644 resources/lang/en_US/api.php create mode 100644 resources/lang/es_ES/api.php create mode 100644 resources/lang/fr_FR/api.php create mode 100644 resources/lang/hu_HU/api.php create mode 100644 resources/lang/id_ID/api.php create mode 100644 resources/lang/it_IT/api.php create mode 100644 resources/lang/nb_NO/api.php create mode 100644 resources/lang/nl_NL/api.php create mode 100644 resources/lang/pl_PL/api.php create mode 100644 resources/lang/pt_BR/api.php create mode 100644 resources/lang/ro_RO/api.php create mode 100644 resources/lang/ru_RU/api.php create mode 100644 resources/lang/tr_TR/api.php create mode 100644 resources/lang/zh_CN/api.php create mode 100644 resources/lang/zh_TW/api.php diff --git a/app/Api/V1/Controllers/AttachmentController.php b/app/Api/V1/Controllers/AttachmentController.php index 3e3bc6febc..e5a3a93d84 100644 --- a/app/Api/V1/Controllers/AttachmentController.php +++ b/app/Api/V1/Controllers/AttachmentController.php @@ -98,15 +98,15 @@ class AttachmentController extends Controller public function download(Attachment $attachment): LaravelResponse { if (false === $attachment->uploaded) { - throw new FireflyException('No file has been uploaded for this attachment (yet).'); + throw new FireflyException(trans('api.error_no_upload')); } if (0 === $attachment->size) { - throw new FireflyException('No file has been uploaded for this attachment (yet).'); + throw new FireflyException(trans('api.error_no_upload')); } if ($this->repository->exists($attachment)) { $content = $this->repository->getContent($attachment); if ('' === $content) { - throw new FireflyException('No file has been uploaded for this attachment (yet).'); + throw new FireflyException(trans('api.error_no_upload')); } $quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\')); @@ -125,7 +125,7 @@ class AttachmentController extends Controller return $response; } - throw new FireflyException('Could not find the indicated attachment. The file is no longer there.'); + throw new FireflyException(trans('api.error_file_lost')); } /** diff --git a/app/Api/V1/Controllers/BillController.php b/app/Api/V1/Controllers/BillController.php index 0dd134b670..9e9424a1bb 100644 --- a/app/Api/V1/Controllers/BillController.php +++ b/app/Api/V1/Controllers/BillController.php @@ -223,7 +223,7 @@ class BillController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); } - throw new FireflyException('Could not store new bill.'); // @codeCoverageIgnore + throw new FireflyException(trans('api.error_store_bill')); // @codeCoverageIgnore } diff --git a/app/Api/V1/Controllers/BudgetController.php b/app/Api/V1/Controllers/BudgetController.php index 4397dc34b6..5ea5793cf7 100644 --- a/app/Api/V1/Controllers/BudgetController.php +++ b/app/Api/V1/Controllers/BudgetController.php @@ -199,7 +199,7 @@ class BudgetController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); } - throw new FireflyException('Could not store new budget.'); // @codeCoverageIgnore + throw new FireflyException(trans('api.error_store_budget')); // @codeCoverageIgnore } /** diff --git a/app/Api/V1/Controllers/BudgetLimitController.php b/app/Api/V1/Controllers/BudgetLimitController.php index 73f9e7d915..a7158c8dac 100644 --- a/app/Api/V1/Controllers/BudgetLimitController.php +++ b/app/Api/V1/Controllers/BudgetLimitController.php @@ -165,7 +165,7 @@ class BudgetLimitController extends Controller $data = $request->getAll(); $budget = $this->repository->findNull($data['budget_id']); if (null === $budget) { - throw new FireflyException('Unknown budget.'); + throw new FireflyException(trans('error_unknown_budget')); } $data['budget'] = $budget; $budgetLimit = $this->blRepository->storeBudgetLimit($data); diff --git a/app/Api/V1/Controllers/CategoryController.php b/app/Api/V1/Controllers/CategoryController.php index a992314676..1f808f5b60 100644 --- a/app/Api/V1/Controllers/CategoryController.php +++ b/app/Api/V1/Controllers/CategoryController.php @@ -163,7 +163,7 @@ class CategoryController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); } - throw new FireflyException('Could not store new category.'); // @codeCoverageIgnore + throw new FireflyException(trans('error_store_new_category')); // @codeCoverageIgnore } /** diff --git a/app/Api/V1/Controllers/ConfigurationController.php b/app/Api/V1/Controllers/ConfigurationController.php index 0a58218c64..28a099f114 100644 --- a/app/Api/V1/Controllers/ConfigurationController.php +++ b/app/Api/V1/Controllers/ConfigurationController.php @@ -57,7 +57,7 @@ class ConfigurationController extends Controller $admin = auth()->user(); if (!$this->repository->hasRole($admin, 'owner')) { - throw new FireflyException('No access to method.'); // @codeCoverageIgnore + throw new FireflyException(trans('error_no_access')); // @codeCoverageIgnore } return $next($request); diff --git a/app/Api/V1/Controllers/CurrencyController.php b/app/Api/V1/Controllers/CurrencyController.php index fce426ff0d..550820bcf6 100644 --- a/app/Api/V1/Controllers/CurrencyController.php +++ b/app/Api/V1/Controllers/CurrencyController.php @@ -313,10 +313,10 @@ class CurrencyController extends Controller if (!$this->userRepository->hasRole($admin, 'owner')) { // access denied: - throw new FireflyException('No access to method, user is not owner.'); // @codeCoverageIgnore + throw new FireflyException(trans('api.error_no_access_ownership')); // @codeCoverageIgnore } if ($this->repository->currencyInUse($currency)) { - throw new FireflyException('No access to method, currency is in use.'); // @codeCoverageIgnore + throw new FireflyException(trans('api.error_no_access_currency_in_use')); // @codeCoverageIgnore } $this->repository->destroy($currency); @@ -592,7 +592,7 @@ class CurrencyController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); } - throw new FireflyException('Could not store new currency.'); // @codeCoverageIgnore + throw new FireflyException(trans('api.error_store_new_currency')); // @codeCoverageIgnore } diff --git a/app/Api/V1/Controllers/CurrencyExchangeRateController.php b/app/Api/V1/Controllers/CurrencyExchangeRateController.php index 53886a9158..330f93f741 100644 --- a/app/Api/V1/Controllers/CurrencyExchangeRateController.php +++ b/app/Api/V1/Controllers/CurrencyExchangeRateController.php @@ -79,10 +79,10 @@ class CurrencyExchangeRateController extends Controller $toCurrency = $this->repository->findByCodeNull($request->get('to') ?? 'USD'); if (null === $fromCurrency) { - throw new FireflyException('Unknown source currency.'); + throw new FireflyException(trans('api.error_unknown_source_currency')); } if (null === $toCurrency) { - throw new FireflyException('Unknown destination currency.'); + throw new FireflyException(trans('api.error_unknown_destination_currency')); } /** @var Carbon $dateObj */ diff --git a/app/Api/V1/Controllers/LinkTypeController.php b/app/Api/V1/Controllers/LinkTypeController.php index 9db6f52c03..f4a9a38a88 100644 --- a/app/Api/V1/Controllers/LinkTypeController.php +++ b/app/Api/V1/Controllers/LinkTypeController.php @@ -86,7 +86,7 @@ class LinkTypeController extends Controller public function delete(LinkType $linkType): JsonResponse { if (false === $linkType->editable) { - throw new FireflyException(sprintf('You cannot delete this link type (#%d, "%s")', $linkType->id, $linkType->name)); + throw new FireflyException(trans('error_delete_link_type', [':id' => $linkType->id, ':name' => $linkType->name])); } $this->repository->destroy($linkType); @@ -160,7 +160,7 @@ class LinkTypeController extends Controller $admin = auth()->user(); if (!$this->userRepository->hasRole($admin, 'owner')) { - throw new FireflyException('You need the "owner"-role to do this.'); + throw new FireflyException(trans('api.error_owner_role_needed')); } $data = $request->getAll(); // if currency ID is 0, find the currency by the code: @@ -247,14 +247,14 @@ class LinkTypeController extends Controller public function update(LinkTypeRequest $request, LinkType $linkType): JsonResponse { if (false === $linkType->editable) { - throw new FireflyException(sprintf('You cannot edit this link type (#%d, "%s")', $linkType->id, $linkType->name)); + throw new FireflyException(trans('api.error_edit_link_type', [':id' => $linkType->id, ':name' => $linkType->name])); } /** @var User $admin */ $admin = auth()->user(); if (!$this->userRepository->hasRole($admin, 'owner')) { - throw new FireflyException('You need the "owner"-role to do this.'); + throw new FireflyException(trans('api.error_owner_role_needed')); } $data = $request->getAll(); diff --git a/app/Api/V1/Controllers/PiggyBankController.php b/app/Api/V1/Controllers/PiggyBankController.php index c1f44d0b4e..db768a9b7d 100644 --- a/app/Api/V1/Controllers/PiggyBankController.php +++ b/app/Api/V1/Controllers/PiggyBankController.php @@ -192,7 +192,7 @@ class PiggyBankController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json'); } - throw new FireflyException('Could not store new piggy bank.'); + throw new FireflyException(trans('api.error_store_new_piggybank')); } diff --git a/app/Api/V1/Controllers/RecurrenceController.php b/app/Api/V1/Controllers/RecurrenceController.php index 8ed2d10c36..e9ec4302af 100644 --- a/app/Api/V1/Controllers/RecurrenceController.php +++ b/app/Api/V1/Controllers/RecurrenceController.php @@ -236,7 +236,7 @@ class RecurrenceController extends Controller $result = $recurring->fire(); } catch (FireflyException $e) { Log::error($e->getMessage()); - throw new FireflyException('Could not fire recurring cron job.'); + throw new FireflyException(trans('api.error_fire_cronjob')); } if (false === $result) { return response()->json([], 204); diff --git a/app/Api/V1/Controllers/RuleGroupController.php b/app/Api/V1/Controllers/RuleGroupController.php index 120e24b9ac..280d75f494 100644 --- a/app/Api/V1/Controllers/RuleGroupController.php +++ b/app/Api/V1/Controllers/RuleGroupController.php @@ -257,7 +257,7 @@ class RuleGroupController extends Controller /** @var Collection $rules */ $rules = $this->ruleGroupRepository->getActiveRules($group); if (0 === $rules->count()) { - throw new FireflyException('No rules in this rule group.'); + throw new FireflyException(trans('api.error_no_rules_in_rule_group')); } $parameters = $request->getTestParameters(); $matchingTransactions = []; diff --git a/app/Api/V1/Controllers/TransactionLinkController.php b/app/Api/V1/Controllers/TransactionLinkController.php index dbc84a8af3..6e84e6b775 100644 --- a/app/Api/V1/Controllers/TransactionLinkController.php +++ b/app/Api/V1/Controllers/TransactionLinkController.php @@ -165,7 +165,7 @@ class TransactionLinkController extends Controller $inward = $this->journalRepository->findNull($data['inward_id'] ?? 0); $outward = $this->journalRepository->findNull($data['outward_id'] ?? 0); if (null === $inward || null === $outward) { - throw new FireflyException('Source or destination is NULL.'); + throw new FireflyException(trans('error_source_or_dest_null')); } $data['direction'] = 'inward'; @@ -196,7 +196,7 @@ class TransactionLinkController extends Controller $data['inward'] = $this->journalRepository->findNull($data['inward_id'] ?? 0); $data['outward'] = $this->journalRepository->findNull($data['outward_id'] ?? 0); if (null === $data['inward'] || null === $data['outward']) { - throw new FireflyException('Source or destination is NULL.'); + throw new FireflyException(trans('api.error_source_or_dest_null')); } $data['direction'] = 'inward'; $journalLink = $this->repository->updateLink($journalLink, $data); diff --git a/app/Api/V1/Controllers/UserController.php b/app/Api/V1/Controllers/UserController.php index 605ce631b8..da060a25cb 100644 --- a/app/Api/V1/Controllers/UserController.php +++ b/app/Api/V1/Controllers/UserController.php @@ -83,7 +83,7 @@ class UserController extends Controller return response()->json([], 204); } - throw new FireflyException('No access to method.'); // @codeCoverageIgnore + throw new FireflyException(trans('api.error_no_access')); // @codeCoverageIgnore } /** diff --git a/resources/lang/cs_CZ/api.php b/resources/lang/cs_CZ/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/cs_CZ/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/de_DE/api.php b/resources/lang/de_DE/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/de_DE/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/el_GR/api.php b/resources/lang/el_GR/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/el_GR/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/en_US/api.php b/resources/lang/en_US/api.php new file mode 100644 index 0000000000..b177595e58 --- /dev/null +++ b/resources/lang/en_US/api.php @@ -0,0 +1,45 @@ +. + */ + +declare(strict_types=1); + +return [ + 'error_no_upload' => 'No file has been uploaded for this attachment (yet).', + 'error_file_lost' => 'Could not find the indicated attachment. The file is no longer there.', + 'error_store_bill' => 'Could not store new bill.', + 'error_store_budget' => 'Could not store new budget.', + 'error_unknown_budget' => 'Unknown budget.', + 'error_store_new_category' => 'Could not store new category.', + 'error_no_access' => 'No access to method.', + 'error_no_access_ownership' => 'No access to method, user is not owner.', + 'error_no_access_currency_in_use' => 'No access to method, currency is in use.', + 'error_store_new_currency' => 'Could not store new currency.', + 'error_unknown_source_currency' => 'Unknown source currency.', + 'error_unknown_destination_currency' => 'Unknown destination currency.', + 'error_delete_link_type' => 'You cannot delete this link type (:id, :name)', + 'error_edit_link_type' => 'You cannot edit this link type (:id, :name)', + 'error_owner_role_needed' => 'You need the "owner"-role to do this.', + 'error_store_new_piggybank' => 'Could not store new piggy bank.', + 'error_fire_cronjob' => 'Could not fire recurring cron job.', + 'error_no_rules_in_rule_group' => 'No rules in this rule group.', + 'error_source_or_dest_null' => 'Source or destination is NULL.' + +]; \ No newline at end of file diff --git a/resources/lang/es_ES/api.php b/resources/lang/es_ES/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/es_ES/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/fr_FR/api.php b/resources/lang/fr_FR/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/fr_FR/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/hu_HU/api.php b/resources/lang/hu_HU/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/hu_HU/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/id_ID/api.php b/resources/lang/id_ID/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/id_ID/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/it_IT/api.php b/resources/lang/it_IT/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/it_IT/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/nb_NO/api.php b/resources/lang/nb_NO/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/nb_NO/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/nl_NL/api.php b/resources/lang/nl_NL/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/nl_NL/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/pl_PL/api.php b/resources/lang/pl_PL/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/pl_PL/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/pt_BR/api.php b/resources/lang/pt_BR/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/pt_BR/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/ro_RO/api.php b/resources/lang/ro_RO/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/ro_RO/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/ru_RU/api.php b/resources/lang/ru_RU/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/ru_RU/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/tr_TR/api.php b/resources/lang/tr_TR/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/tr_TR/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/zh_CN/api.php b/resources/lang/zh_CN/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/zh_CN/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file diff --git a/resources/lang/zh_TW/api.php b/resources/lang/zh_TW/api.php new file mode 100644 index 0000000000..c0daaf8ad9 --- /dev/null +++ b/resources/lang/zh_TW/api.php @@ -0,0 +1,26 @@ +. + */ + +declare(strict_types=1); + +return [ + +]; \ No newline at end of file