yii-starter-kit / yii2-starter-kit

Yii2 Starter Kit
http://yii2-starter-kit.terentev.net
Other
1.42k stars 648 forks source link

when choosing langue with zh-CN, widget WYSIWYG editor can not loaded #753

Closed DoveShy closed 4 years ago

DoveShy commented 4 years ago

the reason is widget asofter/yii2-imperavi-redactor has two mistakes the correct code is as follows:

class yii\imperavi\widget:

/**
     * Registers Imperavi Redactor JS
     */
    protected function registerClientScript()
    {
        $view = $this->getView();

        /*
         * Language fix
         * @author <https://github.com/sim2github>
         */
        if (!isset($this->options['lang']) || empty($this->options['lang'])) {
            $lang = strtolower(substr(Yii::$app->language, 0, 2));
            //insert code
            if ($lang == 'zh') {
                $lang = 'zh_cn';
            }
            $this->options['lang'] = $lang;
        }
        //insert code
        if ($this->options['lang'] != 'en' &&  $this->options['lang'] != 'zh') {
            // Kudos to yiidoc/yii2-redactor for this solution
            $this->assetBundle->js[] = 'lang/' . $this->options['lang'] . '.js';
        }

class yii\imperavi\ImperaviRedactorAsset

public function init() {
        $appLanguage = strtolower(substr(Yii::$app->language , 0, 2)); // First 2 letters
        // insert code 
        if ($appLanguage == 'zh') {
            $appLanguage = 'zh_'.strtolower(substr(Yii::$app->language , 3, 5));
        }

        if($appLanguage != 'en' && file_exists(Yii::getAlias('@yii/imperavi/assets') . '/lang/' . $appLanguage . '.js')){
            $this->js[] = 'lang/' . $appLanguage . '.js';
        }
        parent::init();
    }
XzAeRo commented 4 years ago

We do not maintain that package. I would suggest going to that project and ask for changes: https://github.com/asofter/yii2-imperavi-redactor

But considering that the package was last updated 3+ years ago, we might need to consider switching packages here...