[][src]Macro gettext_macros::init_i18n

init_i18n!() { /* proc-macro */ }

This macro configures internationalization for the current crate

This macro expands to nothing, it just write your configuration to files for other macros calls, and creates the .pot file if needed.

This macro should be called before (not in the program flow, but in the Rust parser flow) all other internationalization macros.

Examples

Basic usage:

This example is not tested
init_i18n!("my_app", de, en, eo, fr, ja, pl, ru);

With .po and .mo generation turned off, and without comments about string location in the .pot:

This example is not tested
init_i18n!("my_app", po = false, mo = false, de, en, eo, fr, ja, pl, ru);

Syntax

This macro expects:

  • a string literal, that is the translation domain of your crate.
  • optionally, the po named argument, that is a boolean literal to turn off .po generation from .pot in compile_i18n
  • optionally, the mo named argument, that is a boolean literal too, to turn of .po compilation into .mo files in compile_i18n. Note that if you turn this feature off, include_i18n won't work unless you manually generate the .mo files in target/TARGET/gettext_macros/LOCALE/DOMAIN.mo.
  • optionally, the location named argument, a boolean too, to avoid writing the location of the string in the source code to translation files. Having this location available can be usefull if your translators know a bit of Rust and needs context about what they are translating, but it also makes bigger diffs, because your .pot and .po files may be regenerated if a line number changes.
  • then, the list of languages you want your app to be translated in, separated by commas. The languages are not string literals, but identifiers.

All the three boolean options are turned on by default. Also note that you may ommit one (or more) of them, but they should always be in this order.