summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2023-04-13 10:06:21 +0200
committerGitHub <noreply@github.com>2023-04-13 10:06:21 +0200
commit836c63c5d9770b0f237151860fe29d8b5bb116ab (patch)
tree3ba86eb1576333f2c2b2903e975a3c32db72dae0
parentf95c76d82e5aba7513b8291e78a8e84a2e5aaaef (diff)
parent35b083449a02bd7bdc04e82847a045c4a0d9c9af (diff)
downloadnextcloud-server-836c63c5d9770b0f237151860fe29d8b5bb116ab.tar.gz
nextcloud-server-836c63c5d9770b0f237151860fe29d8b5bb116ab.zip
Merge pull request #37705 from nextcloud/backport/37704/stable26
[stable26] fix(translation): Fix several issues with the translations api
-rw-r--r--core/Controller/TranslationApiController.php22
1 files changed, 16 insertions, 6 deletions
diff --git a/core/Controller/TranslationApiController.php b/core/Controller/TranslationApiController.php
index 9cdfbf4a151..a09f7e6aba9 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,15 +37,22 @@ 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;
}
/**
- * @NoAdminRequired
+ * @PublicPage
*/
public function languages(): DataResponse {
return new DataResponse([
@@ -54,7 +62,9 @@ class TranslationApiController extends \OCP\AppFramework\OCSController {
}
/**
- * @NoAdminRequired
+ * @PublicPage
+ * @UserRateThrottle(limit=25, period=120)
+ * @AnonRateThrottle(limit=10, period=120)
*/
public function translate(string $text, ?string $fromLanguage, string $toLanguage): DataResponse {
try {
@@ -62,11 +72,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_BAD_REQUEST);
} 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_BAD_REQUEST);
}
}
}