Internationalise a Rust program and translate strings quickly and simply. Make any software open to multiple languages
In your "Cargo.toml" file :
toml
[dependencies]
lingo_lib = "*"
Check the current version on crates.io.
Unfortunately, the crate "lingo" already exists in crates.io. Waiting to get the name, be careful to not import "lingo" but "lingo_lib".
```rust
let mut lingo = lingo![
(
"
// If not set, it's the operating system locale that will be used.
lingo.setcontextlocale(/* app locale /);
// If not set, it's locale!("en")
.
lingo.set_default_locale(/ locale */);
println!("{}", lingo.string("
```rust locale!("en"); // English (no country code) locale!("en_US"); // English (United States)
Locale::fromstring("enUS", ''); // English (United States) Locale::fromstring("en-US", '-'); // English (United States)
// English (no country code) Locale(Language::new(LanguageCode::en), CountryCode::None); // English (United States) Locale(Language::new(LanguageCode::en), CountryCode::US); ```
A French application using lingo
.
```rust
let mut lingo = lingo![
(
"helloworld",
strings![
s!("frBE", "Bonjour le monde !"), // Belgium
s!("enGB", "Hello world!")
]
),
(
"love",
strings![
s!("frFR", "J'adore Lingo"), // France
s!("en_GB", "I love Lingo")
]
)
];
lingo.setcontextlocale(locale!("frFR")); lingo.setdefaultlocale(locale!("frFR"));
println!("{}", lingo.string("hello_world").unwrap()); println!("{}", lingo.string("love").unwrap()); ```
Bonjour le monde !
J'adore Lingo
If there were no fr
string, it would use : s!("en_GB", "Hello world!")
.
```rust use std::collections::HashMap;
use lingolib::locales::Locale; use lingolib::strings::getstring; use lingolib::Lingo; use lingo_lib::{lingo, locale, s, strings}; ```