use getLanguages

This commit is contained in:
Avinash Gusain 2023-12-13 16:07:44 +05:30
parent 3a46916ad9
commit d1e6ea379e
2 changed files with 8 additions and 11 deletions

View file

@ -248,14 +248,11 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
public function FilterLanguage(&$sLanguage, $bAdmin) : void public function FilterLanguage(&$sLanguage, $bAdmin) : void
{ {
if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) { if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) {
$aResultLang = \json_decode(\file_get_contents(APP_VERSION_ROOT_PATH . 'app/localization/langs.json'), true); $aResultLang = \SnappyMail\L10n::getLanguages(false);
if ($aResultLang === null) {
throw new \Exception('Error decoding JSON content.');
}
$user = \OC::$server->getUserSession()->getUser(); $user = \OC::$server->getUserSession()->getUser();
$userId = $user->getUID(); $userId = $user->getUID();
$userLang = \OC::$server->getConfig()->getUserValue($userId, 'core', 'lang','en'); $userLang = \OC::$server->getConfig()->getUserValue($userId, 'core', 'lang','en');
$sLanguage = $this->determineLocale($userLang,$aResultLang['LANGS_NAMES_EN']); $sLanguage = $this->determineLocale($userLang,$aResultLang);
// Check if $sLanguage is null // Check if $sLanguage is null
if ($sLanguage === null) { if ($sLanguage === null) {
$sLanguage = 'en'; // Assign 'en' if $sLanguage is null $sLanguage = 'en'; // Assign 'en' if $sLanguage is null
@ -273,20 +270,20 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
*/ */
private function determineLocale (string $langCode, array $languagesArray) : string { private function determineLocale (string $langCode, array $languagesArray) : string {
// Direct check for the language code // Direct check for the language code
if (isset($languagesArray[$langCode])) { if (in_array($langCode, $languagesArray)) {
return $langCode; return $langCode;
} }
// Check with uppercase country code // Check with uppercase country code
$langCodeWithUpperCase = $langCode . '-' . strtoupper($langCode); $langCodeWithUpperCase = $langCode . '-' . strtoupper($langCode);
if (isset($languagesArray[$langCodeWithUpperCase])) { if (in_array($langCodeWithUpperCase, $languagesArray)) {
return $langCodeWithUpperCase; return $langCodeWithUpperCase;
} }
// Iterating to find a match starting with langCode // Iterating to find a match starting with langCode
foreach ($languagesArray as $localeKey => $localeValue) { foreach ($languagesArray as $localeValue) {
if (strpos($localeKey, $langCode) === 0) { if (strpos($localeValue, $langCode) === 0) {
return $localeKey; return $localeValue;
} }
} }

View file

@ -8,7 +8,7 @@ abstract class L10n
/** /**
* @staticvar array $aCache * @staticvar array $aCache
*/ */
public static function getLanguages(bool $bAdmin = false) : array public static function (bool $bAdmin = false) : array
{ {
static $aCache = array(); static $aCache = array();