Overview
Faculty Bot uses rosetta-i18n for internationalization, supporting multiple languages including English, German, and Japanese.How It Works
Build-Time Code Generation
Translation files are compiled into Rust code at build time usingbuild.rs:
build.rs
Translation Module
Translations are included in the main module:src/main.rs
Translation Files
English (en.json)
i18n/en.json
German (de.json)
i18n/de.json
Japanese (ja.json)
Japanese translations follow the same structure (not fully implemented in the source).Using Translations in Commands
Basic Usage
src/commands/user.rs
With Parameters
Some translation strings support placeholders:Command Localization
Poise supports localizing command names and descriptions:Localized Command Names
- English users see:
/verify - German users see:
/verifizieren - Japanese users see:
/確認
Localized Descriptions
Localized Parameters
Adding New Translations
Add Translation Key
Add the new key to all translation files:i18n/en.json:i18n/de.json:i18n/ja.json:
Translation String Formats
Simple Strings
With Parameters
With Multiple Parameters
Locale Detection
Poise automatically provides the user’s Discord locale:Common Discord Locales
"en-US": English (United States)"en-GB": English (United Kingdom)"de": German"ja": Japanese"es-ES": Spanish (Spain)"fr": French"zh-CN": Chinese (Simplified)
Best Practices
- Always provide fallback: Default to English if locale is unknown
- Keep keys semantic: Use descriptive key names like
err_invalid_email - Maintain consistency: Keep the same keys across all language files
- Use placeholders wisely: Make parameters generic and reusable
- Test all languages: Verify translations work in different locales
- Handle missing translations: Rosetta-i18n falls back to the default language if a key is missing
- Keep translations short: Discord has character limits for embeds and messages
Translation Guidelines
For Error Messages
err_ for clarity.
For User Actions
For Instructions
Adding a New Language
Troubleshooting
Translation Key Not Found
Error:method not found in Lang
Solution: Ensure the key exists in all translation files and rebuild:
Wrong Language Displayed
Issue: User sees wrong language Solution: Check locale detection logic and ensure the locale string matches Discord’s format.Build Errors
Error:failed to run custom build command for rosetta-build
Solution: Verify all translation files are valid JSON:
Resources
Next Steps
- Review Command Examples
- Understand Error Handling
- Explore existing translations in
i18n/directory