Yii 哎。细枝模式中的国际化

Yii 哎。细枝模式中的国际化,yii,twig,Yii,Twig,如何在细枝模式中传递方法Yii::t() 能够使用它。 例如: {{Yii.t('main', 'some_text')}} 我自己已经明白了。 谁能派上用场: 在init函数中的文件:/protected/extensions/ETwigViewRenderer.php中添加: $Yii=新的EwigViewRenderStaticClassProxy('Yii') $this->_twig->addGlobal('lang',$Yii) 按以下方式使用树枝内模板: {{lang.t('

如何在细枝模式中传递方法Yii::t() 能够使用它。
例如:

{{Yii.t('main', 'some_text')}}  

我自己已经明白了。
谁能派上用场:
在init函数中的文件:/protected/extensions/ETwigViewRenderer.php中添加:

$Yii=新的EwigViewRenderStaticClassProxy('Yii')
$this->_twig->addGlobal('lang',$Yii)

按以下方式使用树枝内模板:

{{lang.t('main','Login')}}
{{lang.t('main','Logout({username}),{{{username}':App.user.name}}


然后你可以在你的小枝文件上使用t('main','sometext')

@extends Eugene answer

最好在配置中定义全局,而不要编辑扩展名文件:

'view' => [
            'class' => 'yii\web\View',
            'renderers' => [
                'twig' => [
                    'class' => 'yii\twig\ViewRenderer',
                    'cachePath' => '@runtime/Twig/cache',
                    // Array of twig options:
                    'options' => [
                        'auto_reload' => true,
                    ],
                    'globals' => ['html' => '\yii\helpers\Html', 'lang' => 'Yii'],
                    'uses' => ['yii\bootstrap'],
                ],
            ],
        ],

注意'globals'设置中的'lang'=>'Yii'。

我想你的意思是{{lang.t('main','Login')}
'view' => [
            'class' => 'yii\web\View',
            'renderers' => [
                'twig' => [
                    'class' => 'yii\twig\ViewRenderer',
                    'cachePath' => '@runtime/Twig/cache',
                    // Array of twig options:
                    'options' => [
                        'auto_reload' => true,
                    ],
                    'globals' => ['html' => '\yii\helpers\Html', 'lang' => 'Yii'],
                    'uses' => ['yii\bootstrap'],
                ],
            ],
        ],