think\Validate使用如何优雅使用多语言?

康康

目前使用官方推荐的think\Validate和symfony/translation,目前在验证文件中使用trans会报错

<?php

namespace app\validate\report;

use think\Validate;

class ReportDetailValidate extends Validate
{
    protected $failException = true;

    protected $rule = [
        'checkId'  => 'require|number'
    ];

    protected $message = [
        'checkId.require' => trans('checkId_require'),
        'checkId.number' => '检查报告ID是数字'
        ];
}

报错:
PHP Fatal error:  Constant expression contains invalid operations in ...

有其他方案实现吗?有没有自动优雅的使用方式。

1021 1 0
1个回答

yzh52521
年代过于久远,无法发表回答
🔝