'How to completely control Laravel Excel customValidationMessages output messages?

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



Solution 1:[1]

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)",

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chinh Nguyen