在yii2:为什么我的默认语言是en

时间:2017-07-23 06:54:39

标签: yii yii2

如何将默认语言从en更改为另一种语言

$config = [
    'on beforeAction' => function ($event)
        {
        Yii::$app->language = 'fa';
        },
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'language' => '/fa',
    'components' => [
        'jdate' => [
            'class' => 'jDate\DateTime'
        ],
        'mycomponent' => [
            'class' => 'app\components\MyComponent',
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '******',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'urlManager' => [
            'class' => 'codemix\localeurls\UrlManager',
            // Disable index.php
            'languages' => ['fa', 'en'], // List all supported languages here
            'showScriptName' => true,
            // Disable r= routes
            'enablePrettyUrl' => true,
            'rules' => array(
//                '' => 'site/index/fa',
//                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
//                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ),
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                    [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
    /*
      'urlManager' => [
      'enablePrettyUrl' => true,
      'showScriptName' => false,
      'rules' => [
      ],
      ],
     */
    ],
    'params' => $params,
];

这是我在web.php中的$ config

我希望将默认值设置为&#39; fa&#39;在根网站!  我的网站自动更改为&#39; en&#39;在任何浏览器中第一次!

我尝试用

更改lang
'on beforeAction' => function ($event)
            {
            Yii::$app->language = 'fa';
            },

但那是正确的工作!

2 个答案:

答案 0 :(得分:1)

删除这个荒谬的onAction&#39; onAction&#39;事情,只是设置

'language' => 'fa', // NOT '/fa'!

答案 1 :(得分:0)

سلام ویدئوهایآقایصیفزادهرومشاهدهکردین? لینکزیرآموزشهایویدئوییایشونهست。 درشمارههای17و18و19 اینموضوعروآموزشدادن。 ASCII