From 15f4ba54df8d2d4b061e0baeb923ec71b7768dd6 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 6 Aug 2024 13:26:36 +0200 Subject: [PATCH] Bugfix: Nextcloud language detection --- plugins/nextcloud/index.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index dd6bc8e25..2ea7a1e1d 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -298,9 +298,10 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin $aResultLang = \SnappyMail\L10n::getLanguages($bAdmin); $userId = \OC::$server->getUserSession()->getUser()->getUID(); $userLang = \OC::$server->getConfig()->getUserValue($userId, 'core', 'lang', 'en'); + $userLang = \strtr($userLang, '_', '-'); $sLanguage = $this->determineLocale($userLang, $aResultLang); // Check if $sLanguage is null - if ($sLanguage === null) { + if (!$sLanguage) { $sLanguage = 'en'; // Assign 'en' if $sLanguage is null } } @@ -321,19 +322,20 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin return $langCode; } + // Check without country code + if (\str_contains($langCode, '-')) { + $langCode = \explode('-', $langCode)[0]; + if (\in_array($langCode, $languagesArray)) { + return $langCode; + } + } + // Check with uppercase country code $langCodeWithUpperCase = $langCode . '-' . \strtoupper($langCode); if (\in_array($langCodeWithUpperCase, $languagesArray)) { return $langCodeWithUpperCase; } - // Iterating to find a match starting with langCode - foreach ($languagesArray as $localeValue) { - if (\str_starts_with($localeValue, $langCode)) { - return $localeValue; - } - } - // If no match is found return null; }