Expand description
Gettext translations for Rust desktop apps.
An app embeds its compiled catalogs in the binary and calls init_auto at startup. Code in
the app, and in any library the app depends on, then calls t and nt to get translated
strings.
use patois::{nt, t};
patois::embed_domain!();
fn main() {
patois::init_auto(env!("CARGO_PKG_NAME"));
println!("{}", t("Checking for updates..."));
println!("{}", nt("%d file", "%d files", 3).replacen("%d", "3", 1));
}A library calls t and nt and needs no setup of its own: the strings resolve against the
catalog of the app that uses the library.
Modules§
- wx
- Integration with wxDragon, enabled by the
wxfeature.
Macros§
- embed_
domain - Embeds the compiled catalogs of the calling crate in the binary.
- embed_
wx_ translations - Embeds the
wxstdcatalogs of wxWidgets for the languages that the calling crate ships, and generates aWxStdCatalogLoadertype that serves them.
Structs§
- Language
Info - A language that an app offers.
- Language
Manager - Lists the languages of a domain and switches between them.
Functions§
- available_
locales - Returns the locale codes of the catalogs embedded for
domain. - best_
available_ language - Returns the code of the language in
availablethat best fitssystem_code, orNoneif no language fits. - init
- Sets up translations for an app that loads its catalogs from disk.
- init_
auto - Sets up translations for an app that embeds its catalogs with
embed_domain!. - language_
name - Returns the name of the language
codein that language, orcodeif the language is unknown. - locale
- Returns the active locale in normalized form, such as
pt_BR. - nt
- Returns the form of a plural string that fits
nin the active locale. - set_
default_ domain - Makes
domainthe active domain without registering a locale directory. - set_
locale - Changes the active locale.
- system_
locale - Returns the preferred locale of the operating system in normalized form, such as
en_US. - t
- Returns the translation of
sin the active locale.