Macro tr
macro_rules! tr {
($fmt:literal $(, $($args:tt)*)?) => { ... };
($context:expr; $fmt:literal $(, $($args:tt)*)?) => { ... };
}
Expand description
A convenience macro for using the Object::tr()
and Object::tr_ex()
methods.
Takes a format string literal, with optional arguments. Optionally, context
for potentially ambiguous words can be
added before the format arguments, separated with a ;
.
Using named or positional parameters instead of {}
may make it easier to use dynamic formatting once gdext supports it:
use godot::tools::tr;
// Good.
tr!(context; "{a} is a {b}"); // inlined, with context
tr!("{0} is a {1}", a, b); // positional, without context
tr!("{c} is a {d}", c = a.x, d = b.y); // named (inlining not possible here)
// Not as good, much more fragile.
tr!("{} is a {}", a, b);
The methods are called from the Engine
singleton.
See also: Translation contexts in Godot.