mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
fix(translation): Detect the language first and then ask all providers for translations
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
ac56be10fb
commit
dc67b48c28
1 changed files with 11 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue