ctl10n
ctl10n (compile time localization) provides you a simple way to embed messages
into binary file without embedding them into source. Internally, ctl10n generates
simple macro_rules!
macro tr!()
from provided TOML file with strings.
Basic usage
Put following to your build.rs
:
This will generate file $OUT_DIR/strings.rs
from strings.toml
.
TOML file with strings must be table where all values are strings. Example strings.toml
:
= "Some message"
= "Some message with {arg}"
You should include strings.rs
somewhere (for example, in lib.rs
) to use generated
macro. You can do this by calling macro ctl10n::include_strings!()
or manually,
using include!()
.
After including macro it can be used like this:
!;
include_strings
Output of this code (assuming strings.toml
from above):
Some message
Some message with foobar
Some message with foobaz
Trying to use unknown key or wrong format arguments is compile-time error.