Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(translation): Translate error messages on translations API
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Apr 13, 2023
commit e9cb759c9721047d00957a35adb7cc4e61c789b2
16 changes: 12 additions & 4 deletions core/Controller/TranslationApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,26 @@
use InvalidArgumentException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IL10N;
use OCP\IRequest;
use OCP\PreConditionNotMetException;
use OCP\Translation\ITranslationManager;
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;
}

/**
Expand All @@ -62,11 +70,11 @@ public function translate(string $text, ?string $fromLanguage, string $toLanguag
'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]);
}
}
}