blob: 84628831b5e40167295c80bc7666fafeef108564 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# rust-static-l10n
Static localization for Rust using procedural macros.
`static-l10n` loads translations at compile time and generates match-based
lookups, so missing translations fail the build rather than at runtime.
## Workspace Layout
- `derive/`: proc-macro crate that provides all macros.
- `test/`: example crate used for manual/testing.
## Quick Start
Add metadata in your crate's `Cargo.toml`:
```toml
[package.metadata.static-l10n]
path = "i18n"
base = "en"
langs = ["en", { name = "zh", fallback = "en" }]
```
Put translations under the `path` directory (TOML):
```toml
["Hello, world!"]
en = "Hello, world!"
zh = "你好,世界!"
["Hello, {}!"]
en = "Hello, {}!"
zh = "你好,{}!"
```
Then use the macros in your crate:
```rust
static_l10n::main!();
static_l10n::lang!("zh");
let msg = static_l10n::l10n!("Hello, world!");
let formatted = static_l10n::f16n!("Hello, {}!", "Rust");
```
## Rebuild on Translation Changes
`static_l10n::main!()` expands `include_str!` for every translation file, so
editing an existing file triggers a rebuild automatically. New files are not
picked up unless you rebuild or add a `build.rs` that watches the directory.
## Docs
- Macro reference and detailed usage: `derive/README.md`
## Development
Run tests in the example crate:
```bash
cargo test -p static-l10n-test
```
## License
See `LICENSE`.
|