简体   繁体   中英

How can i send parameters to validators.lang.yml in symfony2 validator engine?

I want to translate validation messages in symfony2.

address:
    - NotBlank: { message: "address.address.not_blank" }
    - Length:
        min: 10
        minMessage: "address.address.min_length"

I want to show min or max limit parameter.

address.address.min_length: Address must be at least %limit% characters length

But this isn't working!

My translation file name is validators.en.yml.

Users getting error message exactly like this. They are not able to see

%limit%

How can i show them limit parameter?

According to the official documentation you should use token:

{{ limit }}

and not

%limit%

Now, if you want to supply some parameters that are not strictly bound for the Length validator you should probably implement your own validator with translator service as an argument. Then it would be just as easy to use it as Length inside configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM