提问人:miken32 提问时间:10/6/2018 更新时间:10/6/2018 访问量:136
Artisan 控制台命令的本地化
Localization of an Artisan console command
问:
我正在为我的 Laravel 应用程序编写一个命令行程序,并希望它是可本地化的。由于命令的帮助文本被定义为类变量的一部分,因此我尝试像这样创建它:$signature
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = sprintf(
"myapp:command {--i|id %s}",
__("This is some help text for the ID")
);
但是,我收到以下错误消息:
PHP 致命错误:常量表达式包含无效操作
我假设类变量的处理方式有点像常量,那么我如何为帮助文本提供一个正确可本地化的字符串呢?有没有办法在对象实例化后提供文本?protected
答:
3赞
Devon Bessemer
10/6/2018
#1
函数不能在属性声明中使用,但它们可以在构造函数中使用,这工作正常:
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
$this->signature = sprintf(
"myapp:command {--i|id %s}",
__("This is some help text for the ID")
);
parent::__construct();
}
评论
0赞
miken32
10/6/2018
这很容易。谢谢!
评论