'简体中文', 'en-US' => 'English' ]; public $info = [ 'author' => 'nodelog', 'version' => 'v1.0', 'id' => 'locale', 'name' => '本地化', 'description' => '本地化' ]; public function frontend($app) { Event::on(View::className(), 'beforeRenderRightMenu', [$this, 'handle']); $app->attachBehavior('locale', [ 'class' => 'plugins\locale\LocaleBehavior', 'enablePreferredLanguage' => true ]); $config = $this->getConfig(); $app->controllerMap['locale'] = [ 'class' => DefaultController::className(), 'config' => $config ]; } public function handle($event) { $config = $this->getConfig(); $event->sender->params['rightMenuItems'][] = [ 'label'=>Yii::t('app', 'Language'), 'items'=>array_map(function ($code) use ($config) { return [ 'label' => self::$language[$code], 'url' => ['/locale/set', 'locale' => $code], 'active' => Yii::$app->language === $code ]; }, $config['availableLocales']) ]; } }