2025-12-18 01:11:17 +00:00
..
2025-12-18 01:11:17 +00:00
2025-12-18 01:11:17 +00:00
2025-12-18 01:11:17 +00:00

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

Form Definition with i18n

Forms use language keys instead of hardcoded text:

[fields.email]
type = "email"
label = "fields.email.label"  # References translation key
help_text = "fields.email.help"

Translation Files

Translations are stored in locales/ directory:

locales/
├── en.json
├── es.json
├── fr.json
└── de.json

Translation Format

{
  "fields": {
    "email": {
      "label": "Email Address",
      "help": "Enter your email address"
    }
  }
}

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)