-
Couldn't load subscription status.
- Fork 777
Description
Description
I'm using the Respect Validation library within the Webman framework, and the validation error messages are being returned in Chinese by default. I would like to change the error messages to English.
Steps to Reproduce
- Install and configure Webman with Respect Validation. Or you can use my minimal reproduction : https://github.com/coding-enjoyer/Repro-Webman-Respect-Validation
- Run composer install, and start the server using : php start.php start
- Send POST request to http://localhost:8787/auth/login with empty JSON to trigger validation error.
- Observe the json response that the validation message is returned in Chinese.
Expected Behavior
Validation error messages should be returned in English by default, or there should be an easy way to configure the default language.
Current Behavior
The validation messages are returned in Chinese, and I haven't found a way to switch them to English.
trait HasValidation
{
public array $validationResult = [];
public function check(): ?array
{
if (count($this->validationResult) > 0) {
return $this->validationResult;
}
return null;
}
}Example of name validation :
class UserEntity extends BaseEntity
{
use HasValidation;
public function __construct(
public mixed $name,
public mixed $password,
public mixed $email,
) {}
public function validateName()
{
try {
(new Rules\AllOf(
new Rules\Alnum(),
new Rules\NoWhitespace(),
new Rules\Length(1, 255)
))->assert($this->name);
} catch (ValidationException $e) {
$this->validationResult['name'] = $e->getMessage();
}
return $this;
}class AuthController
{
public function index(Request $request)
{
Factory::setDefaultInstance(
(new Factory())->withTranslator('gettext')
);
$validation = (new UserEntity(
name: $request->input('name'),
password: $request->input('password'),
email: $request->input('email')
))->validateName()
->validatePassword()
->validateEmail()
->check();
return json(['code' => 0, 'msg' => 'ok', 'data' => $validation]);
}
}Environment
PHP version: 8.3.12
Webman version: 1.5.0
Workerman/Respect Validation version : 3.1
Respect/Validation version: X.X.X
Additional Context
I've changed the default locale to "en" but no result.
I've checked the documentation but couldn't find a clear way to set the language for validation messages in Webman.
