summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-05-01 15:05:43 +0200
committerJoas Schilling <coding@schilljs.com>2023-05-02 16:38:33 +0200
commitdc67b48c28c37d77b29b9b9ed987d0664811eddf (patch)
tree3d889186f0423d9bc19a030502a16b368e7c81ce
parentac56be10fbd02c09bdeebcaa69d57aaae6613b9f (diff)
downloadnextcloud-server-dc67b48c28c37d77b29b9b9ed987d0664811eddf.tar.gz
nextcloud-server-dc67b48c28c37d77b29b9b9ed987d0664811eddf.zip
fix(translation): Detect the language first and then ask all providers for translations
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/private/Translation/TranslationManager.php14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/private/Translation/TranslationManager.php b/lib/private/Translation/TranslationManager.php
index ec829e83255..3fded754f6a 100644
--- a/lib/private/Translation/TranslationManager.php
+++ b/lib/private/Translation/TranslationManager.php
@@ -63,15 +63,23 @@ class TranslationManager implements ITranslationManager {
throw new PreConditionNotMetException('No translation providers available');
}
- foreach ($this->getProviders() as $provider) {
- if ($fromLanguage === null && $provider instanceof IDetectLanguageProvider) {
- $fromLanguage = $provider->detectLanguage($text);
+ if ($fromLanguage === null) {
+ foreach ($this->getProviders() as $provider) {
+ if ($provider instanceof IDetectLanguageProvider) {
+ $fromLanguage = $provider->detectLanguage($text);
+ }
+
+ if ($fromLanguage !== null) {
+ break;
+ }
}
if ($fromLanguage === null) {
throw new InvalidArgumentException('Could not detect language');
}
+ }
+ foreach ($this->getProviders() as $provider) {
try {
return $provider->translate($fromLanguage, $toLanguage, $text);
} catch (RuntimeException $e) {