Macro godot::tools::tr_n

macro_rules! tr_n {
    ($n:expr; $singular:literal, $plural:literal $(, $($args:tt)*)?) => { ... };
    ($n:expr, $context:expr; $singular:literal, $plural:literal $(, $($args:tt)*)?) => { ... };
}
Expand description

A convenience macro for using the Object::tr_n() and Object::tr_n_ex() methods.

Allows for the use of format strings with arbitrary arguments. n is given prior to the format string, followed by ;. Optionally, context for potentially ambiguous words can be added with , after n and before ;.

Using named or positional parameters instead of {} may make it easier to use dynamic formatting once gdext supports it:

use godot::tools::tr_n;

// Good.
tr_n!(n, context; "{a} is a {b}", "{a}s are {b}s"); // inlined, with context
tr_n!(n; "{0} is a {1}", "{0}s are {1}s", a, b); // positional, without context
tr_n!(n; "{c} is a {d}", "{c}s are {d}s", c = a.x, d = b.y); // named (inlining not possible here)

// Not as good, much more fragile.
// Additionally, such syntax requires that BOTH format strings use ALL listed arguments.
tr_n!(n; "{} is a {}", "{}s are {}s", a, b);

The methods are called from the Engine singleton.

See also: Translation contexts in Godot.