如何完全控制Laravel Excel Custom ValidationMessages输出消息?
我目前正在使用Laravel Excel将Excel文件的数据导入数据库。当发生一些错误时,我希望它用外语报告,而不是用英语报告,我知道我必须使用customValidationMessages()函数来定义输出消息。
这是常规消息的一个示例:
第2行上有一个错误。
已经采取了某个场地。
第3行发生了一个错误。
由2部分组成
行{some_row}上存在错误。是第一部分。
和
某个菲尔德已经被采取了。是最后一部分
,当我遵循此处提供的文档时noreferrer“> https://docs.laravel-excel.com/3.1/imports/validation.html#custom-validation-messages 我可以在外语中输出的只是最后一部分,但第一部分仍然保留像这样的英语。
第2行上有错误。 第3行中有一个错误。ข้อความในภาษาต่างประเทศ
。
ข้อความภาษาต่างประเทศแถวที่2。ข้อความในภาษาต่างประเทศ
ข้อความภาษาต่างประเทศแถวที่3。
我该怎么做???
提前谢谢大家
I am currently using Laravel Excel to import data from an excel file into database. When there are some errors occur, I'd like it to report in a foreign language rather than in English which I know I have to use customValidationMessages() function to define the output messages.
This is an example of regular messages:
There was an error on row 2. The somefield has already been taken.
There was an error on row 3. The somefield has already been taken.
Which consists of 2 parts
There was an error on row {some_row}. is the first part.
and
The somefield has already been taken. is the last part
and when I follow the document provided here https://docs.laravel-excel.com/3.1/imports/validation.html#custom-validation-messages all I can output in the foreign language is just the last part but the first part remains in English like this.
There was an error on row 2. ข้อความในภาษาต่างประเทศ
There was an error on row 3. ข้อความในภาษาต่างประเทศ
But I want it to be like this
ข้อความภาษาต่างประเทศแถวที่ 2. ข้อความในภาษาต่างประเทศ
ข้อความภาษาต่างประเทศแถวที่ 3. ข้อความในภาษาต่างประเทศ
How can I do it???
Thank you all in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在检查库源后,看起来他们也将Laravel的本地化用于该部分:
__('Row:row。:Message。:Message',['row'=> $ gt; $ this->行,'消息'=> $ message]);
https://github.com/SpartnerNL/Laravel-Excel/blob/44e165b73eaf182a2f699d905a20684889675b1c/src/Validators/Failure.php#L82
so you can define your own localization message like:
“行上有一个错误:行。:消息” => “ข้อความภาษาต่างประเทศแถวที่2(更改您自己的消息,因为我真的不知道您的语言)”,
after inspect the library source, it looks like they use the laravel's localization for that part too:
__('There was an error on row :row. :message', ['row' => $this->row, 'message' => $message]);
https://github.com/SpartnerNL/Laravel-Excel/blob/44e165b73eaf182a2f699d905a20684889675b1c/src/Validators/Failure.php#L82
so you can define your own localization message like:
"There was an error on row :row. :message" => "ข้อความภาษาต่างประเทศแถวที่ 2 (change to your own message because I don't really know your language)",