From eb550bab957c4bb072a809dbd1b482b79124dc24 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Mon, 16 May 2022 16:45:23 +0200 Subject: [PATCH] Improve language detection. --- ElFinderHelper.php | 32 ++++++++++++++++---------------- ElFinderPopupAction.php | 2 +- ElFinderWidget.php | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ElFinderHelper.php b/ElFinderHelper.php index b679572..2b707f0 100644 --- a/ElFinderHelper.php +++ b/ElFinderHelper.php @@ -80,22 +80,6 @@ public static function registerAssets() { $cs->registerScriptFile($assetsDir . '/js/elfinder.min.js'); } - // elFinder translation - $lang = Yii::app()->language; - if (!in_array($lang, self::$availableLanguages, true)) { - if (strpos($lang, '_')) { - $lang = substr($lang, 0, strpos($lang, '_')); - if (!in_array($lang, self::$availableLanguages, true)) { - $lang = false; - } - } else { - $lang = false; - } - } - if ($lang !== false) { - $cs->registerScriptFile($assetsDir . '/js/i18n/elfinder.' . $lang . '.js'); - } - // some css fixes Yii::app()->clientScript->registerCss( 'elfinder-file-bg-fixer', @@ -146,4 +130,20 @@ public static function importTinyMceFileManager() { Yii::import('ext.tinymce.TinyMceFileManager'); } } + + public static function getLanguage() { + $lang = Yii::app()->language; + if (!in_array($lang, self::$availableLanguages, true)) { + if (strpos($lang, '_')) { + $lang = substr($lang, 0, strpos($lang, '_')); + if (!in_array($lang, self::$availableLanguages, true)) { + $lang = 'en'; + } + } else { + $lang = 'en'; + } + } + + return $lang; + } } diff --git a/ElFinderPopupAction.php b/ElFinderPopupAction.php index f650e70..71cb052 100644 --- a/ElFinderPopupAction.php +++ b/ElFinderPopupAction.php @@ -38,7 +38,7 @@ protected function beforeRun() { throw new CException('$connectorRoute must be set!'); } $this->settings['url'] = $this->controller->createUrl($this->connectorRoute, $this->connectorParams); - $this->settings['lang'] = Yii::app()->language; + $this->settings['lang'] = ElFinderHelper::getLanguage(); $this->settings['baseUrl'] = ElFinderHelper::getAssetsDir() . '/'; $this->settings['soundPath'] = ElFinderHelper::getAssetsDir() . '/sounds/'; diff --git a/ElFinderWidget.php b/ElFinderWidget.php index 58a594f..c52e14a 100644 --- a/ElFinderWidget.php +++ b/ElFinderWidget.php @@ -30,7 +30,7 @@ public function run() { throw new CException('$connectorRoute must be set!'); } $this->settings['url'] = $this->controller->createUrl($this->connectorRoute, $this->connectorParams); - $this->settings['lang'] = Yii::app()->language; + $this->settings['lang'] = ElFinderHelper::getLanguage(); if (Yii::app()->getRequest()->enableCsrfValidation) { $this->settings['customData'] = [