Skip to main content

Crate patois

Crate patois 

Source
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 wx feature.

Macros§

embed_domain
Embeds the compiled catalogs of the calling crate in the binary.
embed_wx_translations
Embeds the wxstd catalogs of wxWidgets for the languages that the calling crate ships, and generates a WxStdCatalogLoader type that serves them.

Structs§

LanguageInfo
A language that an app offers.
LanguageManager
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 available that best fits system_code, or None if 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 code in that language, or code if 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 n in the active locale.
set_default_domain
Makes domain the 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 s in the active locale.