Php Artisan控制台命令的本地化
我正在为我的Laravel应用程序编写一个可本地化的应用程序。由于命令的帮助文本被定义为Php Artisan控制台命令的本地化,php,laravel,laravel-artisan,protected,Php,Laravel,Laravel Artisan,Protected,我正在为我的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
$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
类变量被视为常量,那么如何为帮助文本提供一个可正确本地化的字符串呢?有什么方法可以在对象实例化后提供文本吗?函数不能用于属性声明,但可以用于构造函数,这很好:
/**
* 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();
}
在构造函数中定义签名怎么样?这很简单。谢谢