[英]i18n translations not working in Controller
Why would i18n translations work in a view
, but not in AppController
?为什么 i18n 翻译可以在
view
中工作,而不是在AppController
中?
Doesn't work - In AppController
:不起作用 - 在
AppController
中:
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
debug(__('My English Text'));
...
}
}
Works - In my view
:作品 - 在我
view
:
<p><?= __('My English Text') ?></p>
I simply had to set the language before calling __()
.我只需要在调用
__()
之前设置语言。 In my case, it was being set further down the chain.就我而言,它被设置在链条的更下游。
You can use it like this你可以像这样使用它
$test = __('My English Text');
dd($test);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.