]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(translation): Detect the language first and then ask all providers for translations
authorJoas Schilling <coding@schilljs.com>
Mon, 1 May 2023 13:05:43 +0000 (15:05 +0200)
committerJoas Schilling <coding@schilljs.com>
Tue, 2 May 2023 14:38:33 +0000 (16:38 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Translation/TranslationManager.php

index ec829e832559d87cf99be89155235c92c764e9fb..3fded754f6a0704bb61a2ad0860a490fe364f31f 100644 (file)
@@ -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) {