Keats / validator

Simple validation for Rust structs
MIT License
1.97k stars 141 forks source link

how to do error message localization #280

Closed HosMercury closed 9 months ago

HosMercury commented 9 months ago

how to deal with situations when i need the err msg to change depending on language?

Keats commented 9 months ago

If you have multiple languages, you can use the code (https://github.com/Keats/validator#message-and-code) attribute to fetch the error message in the appropriate language.

HosMercury commented 9 months ago

how code related to the language ?

Keats commented 9 months ago

Think of the code as the key to your i18n translation map, eg regex. Then you can use fluent of gettext to grab the relevant string for the current language code

HosMercury commented 9 months ago

sorry for bothering you

but is not code the name of the attribute( sent from HTML) which is always the same ?

Keats commented 9 months ago

No, code has nothing to do with HTML. It's something you can set for every validator in the derive (but built-in validator have a default code) like in the link in my first derive.