bevy-intl Plugin
A simple internationalization (i18n) plugin for Bevy to manage translations from JSON files. Supports fallback languages, placeholders, plurals, gendered translations, and full WASM compatibility with bundled translations.
Features
- 🌐 WASM Compatible: Automatically bundles translations for web deployment
- 📁 Flexible Loading: Load from filesystem (desktop) or bundled files (WASM)
- 🔧 Feature Flag:
bundle-onlyfeature to force bundled translations on any platform - 🗂️ JSON Organization: Load translations from JSON files organized per language
- 🔄 Translation Support:
- Basic translation
- Placeholders/arguments
- Plural forms
- Gendered text
- 🛡️ Fallback Language: Automatic fallback when translations are missing
- ⚡ Bevy Integration: Native Bevy plugin with resource system integration
🚀 Quick Setup
Add to your Cargo.toml:
[]
= "0.16"
= "0.2.1"
# Optional: Force bundled translations on all platforms
# bevy-intl = { version = "0.2.0", features = ["bundle-only"] }
Initialize the plugin in your Bevy app:
use *;
use ;
// Or with custom configuration
📁 Folder Structure
messages/
├── en/
│ ├── test.json
│ └── another_file.json
├── fr/
│ ├── test.json
│ └── another_file.json
└── es/
├── test.json
└── another_file.json
assets/
src/
🌐 WASM & Platform Behavior
Desktop/Native:
- Loads translations from
messages/folder at runtime - Hot-reloadable during development
- File system access required
WASM/Web:
- Automatically uses bundled translations (compiled at build time)
- No file system access needed
Force Bundled Mode:
= { = "0.2.1", = ["bundle-only"] }
This forces bundled translations on all platforms
📄 JSON Format
Each JSON file can contain either simple strings or nested maps for plurals/genders:
Plural Key Priority (most specific to least):
- Exact count:
"0","1","2","5", etc. - ICU Categories:
"zero","one","two","few","many" - Basic fallback:
"one"vs"other" - Legacy:
"many"as last resort
This supports complex plural rules for languages like:
- English:
one,other - French:
one,many - Polish:
one,few,many - Russian:
one,few,many - Arabic:
zero,one,two,few,many
🔧 API Usage
Accessing translations in systems
use *;
use ;
Changing language
// Method 1: Using App extension trait
// Method 2: Direct resource access
💡 Complete Example
use *;
use ;
Debugging
-
Missing translation files or invalid locales are warned in the console.
-
If a translation is missing, the fallback language will be used, or an "Error missing text" placeholder is returned.
License
This crate is licensed under either of the following, at your option:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be dual licensed as above, without any additional terms or conditions.