Skip to content

Commit

Permalink
Improve language detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 committed May 16, 2022
1 parent b3c7c8d commit eb550ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions ElFinderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion ElFinderPopupAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';

Expand Down
2 changes: 1 addition & 1 deletion ElFinderWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = [
Expand Down

0 comments on commit eb550ba

Please sign in to comment.