https://github.com/antoninhrlt/lingo
Internationalize a Rust program and translate strings quickly and simply. Make any software open to multiple languages
https://github.com/antoninhrlt/lingo
internationalization l10n languages localization rust rust-library software-development
Last synced: 8 months ago
JSON representation
Internationalize a Rust program and translate strings quickly and simply. Make any software open to multiple languages
- Host: GitHub
- URL: https://github.com/antoninhrlt/lingo
- Owner: antoninhrlt
- License: mit
- Created: 2022-12-19T13:32:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-09T21:18:20.000Z (almost 3 years ago)
- Last Synced: 2025-06-21T12:37:42.530Z (about 1 year ago)
- Topics: internationalization, l10n, languages, localization, rust, rust-library, software-development
- Language: Rust
- Homepage: https://crates.io/crates/lingo_lib
- Size: 37.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lingo
Internationalise a Rust program and translate strings quickly and simply. Make any software open to multiple languages
## Installation
In your "Cargo.toml" file :
```toml
[dependencies]
lingo_lib = "*"
```
Check the current version on [crates.io](https://crates.io/crates/lingo_lib).
> Unfortunately, the crate "lingo" already exists in [crates.io](https://crates.io/crates/lingo). Waiting to get the name, be careful to not import "lingo" but "lingo_lib".
## How to use
```rust
let mut lingo = lingo![
(
"",
strings![
s!("", ""),
s!("", "")
// ...
]
)
// ...
];
// If not set, it's the operating system locale that will be used.
lingo.set_context_locale(/* app locale */);
// If not set, it's `locale!("en")`.
lingo.set_default_locale(/* locale */);
println!("{}", lingo.string("").unwrap());
```
- ## Locale
```rust
locale!("en"); // English (no country code)
locale!("en_US"); // English (United States)
Locale::from_string("en_US", '_'); // English (United States)
Locale::from_string("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);
```
## Example
A French application using `lingo`.
```rust
struct MyFrenchApp {
lingo: Lingo,
}
impl MyFrenchApp {
pub fn new() -> Self {
Self {
lingo: Self::init_lingo()
}
}
pub fn run(&self) {
println!("{}", self.lingo.string("welcome").unwrap());
}
}
impl LingoApp for MyFrenchApp {
fn init_lingo() -> Lingo {
let mut lingo = lingo![
(
"welcome",
strings![
s!("fr", "bienvenue sur l'app !"),
s!("en", "welcome to the app!")
// ...
]
)
// ...
];
lingo.set_context_locale(locale!("fr_FR"));
lingo
}
fn lingo(&self) -> &Lingo {
&self.lingo
}
}
fn main() {
let app = MyFrenchApp::new();
println!("{}", app.lingo().string("welcome").unwrap());
app.run();
}
```
```
bienvenue sur l'app !
bienvenue sur l'app !
```
Imports for the example
```rust
use lingo_lib::{ lingo, locale, strings, s };
use lingo_lib::{ Lingo, LingoApp };
use lingo_lib::locales::Locale;
```