translation!() { /* proc-macro */ }Expand description
Macro re-exports.
This use statement re-exports
all the macros on translatable_proc
which only work if included from
this module due to path generation.
translation obtention macro.
This macro generates the way to obtain a translation
from the translation files in the directory defined
in the translatable.toml file.
Parameters
language- A string literal for static inference or an instance oftranslatable::Languagefor dynamic inference.path- A pat prefixed withstaticfor static inference or aVec<impl ToString>for dynamic inference.replacements- Arguments similar to python’skwargsfor the translation replacements.
This macro provides optimizations depending on the dynamism of the parameters while calling the macro.
The optimizations are described the following way
-
If path is static, no runtime lookup will be required
-
If the path is dynamic, the file structure will be hardcoded.
-
If the language is static, the validation will be reported by
rust-analyzer. -
If the language is dynamic the validation will be reported in runtime in the
Errbranch. -
If both are dynamic a single [
String] will be generated.
Independently of any other parameter, the replacements parameter
is always dynamic (context based).
You can shorten it’s invocation if a similar identifier is on scope,
for example x = x can be shortened with x.
Replacement parameters are not validated, if a parameter exists it will be replaced otherwise it won’t.
Returns
A Result containing either:
Ok(String)- If the invocation is successful.Err(translatable::Error)- If the invocation fails with a runtime error.