aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller/TranslationApiController.php
diff options
context:
space:
mode:
authorjld3103 <jld3103yt@gmail.com>2023-03-15 17:29:32 +0100
committerjld3103 <jld3103yt@gmail.com>2023-07-13 07:24:15 +0200
commit1be836273ddba6e0ddb3509a1d898535df9fd169 (patch)
tree5aa57fed3c2173484ffcd082f61aaef5015fc3f3 /core/Controller/TranslationApiController.php
parent706c141fffce928d344fe2f039da549fad065393 (diff)
downloadnextcloud-server-1be836273ddba6e0ddb3509a1d898535df9fd169.tar.gz
nextcloud-server-1be836273ddba6e0ddb3509a1d898535df9fd169.zip
core: Add OpenAPI spec
Signed-off-by: jld3103 <jld3103yt@gmail.com>
Diffstat (limited to 'core/Controller/TranslationApiController.php')
-rw-r--r--core/Controller/TranslationApiController.php18
1 files changed, 17 insertions, 1 deletions
diff --git a/core/Controller/TranslationApiController.php b/core/Controller/TranslationApiController.php
index c1628c24555..3f70a5bcb05 100644
--- a/core/Controller/TranslationApiController.php
+++ b/core/Controller/TranslationApiController.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
+ * @author Kate Döen <kate.doeen@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
@@ -47,10 +48,14 @@ class TranslationApiController extends \OCP\AppFramework\OCSController {
/**
* @PublicPage
+ *
+ * Get the list of supported languages
+ *
+ * @return DataResponse<Http::STATUS_OK, array{languages: array{from: string, fromLabel: string, to: string, toLabel: string}[], languageDetection: bool}, array{}>
*/
public function languages(): DataResponse {
return new DataResponse([
- 'languages' => $this->translationManager->getLanguages(),
+ 'languages' => array_map(fn ($lang) => $lang->jsonSerialize(), $this->translationManager->getLanguages()),
'languageDetection' => $this->translationManager->canDetectLanguage(),
]);
}
@@ -59,6 +64,17 @@ class TranslationApiController extends \OCP\AppFramework\OCSController {
* @PublicPage
* @UserRateThrottle(limit=25, period=120)
* @AnonRateThrottle(limit=10, period=120)
+ *
+ * Translate a text
+ *
+ * @param string $text Text to be translated
+ * @param string|null $fromLanguage Language to translate from
+ * @param string $toLanguage Language to translate to
+ * @return DataResponse<Http::STATUS_OK, array{text: string, from: ?string}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_PRECONDITION_FAILED|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string, from?: ?string}, array{}>
+ *
+ * 200: Translated text returned
+ * 400: Language not detected or unable to translate
+ * 412: Translating is not possible
*/
public function translate(string $text, ?string $fromLanguage, string $toLanguage): DataResponse {
try {