summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-04-13 08:53:15 +0200
committerJoas Schilling <coding@schilljs.com>2023-04-13 08:53:15 +0200
commit21b056ee2d27be0f706584108797058ed316d3cc (patch)
tree5856b27db53e9d77874a88caa5851d9484d44015
parentb1abc57c07a61b5a0557395d86c3e31486a96c23 (diff)
downloadnextcloud-server-21b056ee2d27be0f706584108797058ed316d3cc.tar.gz
nextcloud-server-21b056ee2d27be0f706584108797058ed316d3cc.zip
fix(translation): Translate error messages on translations API
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--core/Controller/TranslationApiController.php16
1 files changed, 12 insertions, 4 deletions
diff --git a/core/Controller/TranslationApiController.php b/core/Controller/TranslationApiController.php
index 9cdfbf4a151..759740d6e90 100644
--- a/core/Controller/TranslationApiController.php
+++ b/core/Controller/TranslationApiController.php
@@ -29,6 +29,7 @@ namespace OC\Core\Controller;
use InvalidArgumentException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
+use OCP\IL10N;
use OCP\IRequest;
use OCP\PreConditionNotMetException;
use OCP\Translation\ITranslationManager;
@@ -36,11 +37,18 @@ use RuntimeException;
class TranslationApiController extends \OCP\AppFramework\OCSController {
private ITranslationManager $translationManager;
+ private IL10N $l;
- public function __construct($appName, IRequest $request, ITranslationManager $translationManager) {
+ public function __construct(
+ string $appName,
+ IRequest $request,
+ ITranslationManager $translationManager,
+ IL10N $l,
+ ) {
parent::__construct($appName, $request);
$this->translationManager = $translationManager;
+ $this->l = $l;
}
/**
@@ -62,11 +70,11 @@ class TranslationApiController extends \OCP\AppFramework\OCSController {
'text' => $this->translationManager->translate($text, $fromLanguage, $toLanguage)
]);
} catch (PreConditionNotMetException) {
- return new DataResponse(['message' => 'No translation provider available'], Http::STATUS_PRECONDITION_FAILED);
+ return new DataResponse(['message' => $this->l->t('No translation provider available')], Http::STATUS_PRECONDITION_FAILED);
} catch (InvalidArgumentException) {
- return new DataResponse(['message' => 'Could not detect language', Http::STATUS_NOT_FOUND]);
+ return new DataResponse(['message' => $this->l->t('Could not detect language'), Http::STATUS_NOT_FOUND]);
} catch (RuntimeException) {
- return new DataResponse(['message' => 'Unable to translate', Http::STATUS_INTERNAL_SERVER_ERROR]);
+ return new DataResponse(['message' => $this->l->t('Unable to translate'), Http::STATUS_INTERNAL_SERVER_ERROR]);
}
}
}