3
votes

I have a standard folder for error messages in Lumen which is similar to Laravel. The problem is that the messages from there are not used. How can I make Lumen to format messages using my translations?

Right now when I dump $validator->errors() it does not format the messages.

MessageBag {#223
  #messages: array:4 [
    "surname" => array:1 [
      0 => "validation.required"
    ]
    "mobile" => array:1 [
      0 => "validation.required"
    ]
    "password" => array:1 [
      0 => "validation.min.string"
    ]
    "email" => array:1 [
      0 => "validation.email"
    ]
  ]
  #format: ":message"
}
1
What language are you using for your application? - krisanalfa
@Alfa I am using English - naneri
Would you mind to share your folder structure? I cannot reproduce this problem. - krisanalfa
@Alfa I use this project and added lang files - github.com/krisanalfa/lumen-jwt - naneri
@Alfa I did find that the app.php config did not have locale set, which cause the trouble. Thanks for pointing me in the right direction. You can post an anser I will mark it as correct. - naneri

1 Answers

13
votes

Basically translator missing locale configuration which should be configured before this instance resolved. Add this to your: config/app.php

/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => env('APP_LOCALE', 'en'),