Internationalization (i18n)
zod-rs includes built-in locale support for validation error messages.
Supported locales
Section titled “Supported locales”| Locale | Language |
|---|---|
Locale::En | English (default) |
Locale::Ar | Arabic |
Use the .local() method on validation errors to get localized messages:
use serde_json::json;use zod_rs::prelude::*;
let schema = object() .field("email", string().ends_with("@domain.com")) .field("password", string().min(8)) .strict();
let input = json!({ "email": "john@example.com", "password": "Strongpassword123"});
match schema.safe_parse(&input) { Ok(output) => println!("Valid: {output}"), Err(err) => println!("{}", err.local(Locale::Ar)),}Contributing translations
Section titled “Contributing translations”Want to add a new language or fix a translation? Contributions are welcome — open an issue or PR on GitHub.