AnyLang - Static Localization for Rust
A Rust proc-macro crate for embedding localization files directly into your binary at compile time. Supports JSON format with TOML support planned for future releases.
Features
- Zero-runtime overhead - All translations are compiled into your binary
- Type-safe - Full Rust type checking for all localized strings
- Hierarchical organization - Nested JSON objects become nested Rust modules
- Multi-format support - JSON with TOML coming soon
- Flexible data types - Supports strings, numbers, booleans, arrays, and null values
Installation
Add to your Cargo.toml:
[]
= { = "0.1", = ["json"] }
Usage
Basic JSON Localization
You can do the arrangement differently, but for convenience I will do it like this:
main.rs
lang/
├── en_US.json
├── ru_RU.json
└── de_DE.json
en_US.json:
ru_RU.json:
Support for non-string types
There is also support for all standard JSON types. Examples below
de_DE.json:
228.01
These examples work in different variations of the main.rs file:
use include_json_dir;
// Include English translations
include_json_dir!;
use include_json_dir;
// Include Russian translations
include_json_dir!;
use include_json_dir;
// Include German translations (simple value)
include_json_dir!;
JSON Array Support
AnyLang also supports JSON arrays as root elements:
en_US.json:
Type Conversion
All JSON types are automatically converted to Rust string types:
- String →
&'static str - Number →
&'static str(string representation) - Boolean →
&'static str("true" or "false") - Null →
&'static str(empty string) - Array →
[&'static str; N] - Object → Rust module with constants
Naming Convention
JSON keys are converted to SCREAMING_SNAKE_CASE for Rust constants:
"foo_bar"becomesFOO_BAR"some_key"becomesSOME_KEY
Roadmap
- JSON support
- TOML support
- YAML support