Internationalization (i18n)
Multi-language form support examples.
Files
- registration_i18n.toml - Registration form with i18n strings
- test_i18n_form.toml - Test form for language support
Usage
Running with Different Languages
# English (default)
LANG=en cargo run --example test_i18n_form
# Spanish
LANG=es cargo run --example test_i18n_form
# French
LANG=fr cargo run --example test_i18n_form
```text
## Form Definition with i18n
Forms use language keys instead of hardcoded text:
```toml
[fields.email]
type = "email"
label = "fields.email.label" # References translation key
help_text = "fields.email.help"
```text
## Translation Files
Translations are stored in `locales/` directory:
```text
locales/
├── en.json
├── es.json
├── fr.json
└── de.json
```text
## Translation Format
```json
{
"fields": {
"email": {
"label": "Email Address",
"help": "Enter your email address"
}
}
}
```text
## Supported Languages
Add translations by creating new locale files:
- `en` - English (default)
- `es` - Spanish
- `fr` - French
- `de` - German
- `ja` - Japanese
- (add more as needed)
## Language Selection
Languages are detected from:
1. `LANG` environment variable
2. `--lang` command-line argument
3. Browser `Accept-Language` header (web)
4. User preference in form
## Best Practices
- Use descriptive translation keys
- Keep translations organized by feature
- Include context for translators
- Test with different language lengths
- Consider RTL languages (Arabic, Hebrew)