| Crates.io | anylang |
| lib.rs | anylang |
| version | 0.0.3 |
| created_at | 2025-11-09 10:18:36.375495+00 |
| updated_at | 2025-11-11 14:38:15.068374+00 |
| description | Crate for generating constants with values at compile time |
| homepage | |
| repository | https://github.com/PuffyWithEyes/anylang |
| max_upload_size | |
| id | 1923941 |
| size | 30,783 |
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.
Add to your Cargo.toml:
[dependencies]
anylang = { version = "0.1", features = ["json"] }
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:
{
"ping": "pong",
"dummy": {
"foo": "buzz",
"some": ["none", "or", 0]
},
"rust": {
"rust": "rust",
"is": null,
"good": {
"true": [1, true]
}
}
}
ru_RU.json:
{
"ping": "понг",
"dummy": {
"foo": "базз",
"some": ["ничего", "или", 0]
},
"rust": {
"rust": "раст",
"is": null,
"good": {
"true": [1, true]
}
}
}
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 anylang::include_json_dir;
// Include English translations
include_json_dir!("./lang", "en_US");
fn main() {
assert_eq!(lang::PING, "pong");
assert_eq!(lang::dummy::FOO, "buzz");
assert_eq!(lang::dummy::SOME, ["none", "or", "0"]);
assert_eq!(lang::rust::RUST, "rust");
assert!(lang::rust::IS.is_empty());
assert_eq!(lang::rust::good::TRUE, ["1", "true"]);
}
use anylang::include_json_dir;
// Include Russian translations
include_json_dir!("./lang", "ru_RU");
fn main() {
assert_eq!(lang::PING, "понг");
assert_eq!(lang::dummy::FOO, "базз");
assert_eq!(lang::dummy::SOME, ["ничего", "или", "0"]);
assert_eq!(lang::rust::RUST, "раст");
assert!(lang::rust::IS.is_empty());
assert_eq!(lang::rust::good::TRUE, ["1", "true"]);
}
use anylang::include_json_dir;
// Include German translations (simple value)
include_json_dir!("./lang", "de_DE");
fn main() {
assert_eq!(lang::DE_DE, "228.01");
}
AnyLang also supports JSON arrays as root elements:
en_US.json:
[
{
"ping": "pong"
},
{
"dummy": {
"some": ["none", "or", 0]
},
"foo": "buzz",
"rust": {
"rust": "rust",
"is": null,
"good": {
"true": [1, true]
}
}
}
]
All JSON types are automatically converted to Rust string types:
&'static str&'static str (string representation)&'static str ("true" or "false")&'static str (empty string)[&'static str; N]JSON keys are converted to SCREAMING_SNAKE_CASE for Rust constants:
"foo_bar" becomes FOO_BAR"some_key" becomes SOME_KEY