Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dsolartec/languages-rs
An internationalization library for your projects
https://github.com/dsolartec/languages-rs
accessibility internationalization localization rust rust-lang
Last synced: 8 days ago
JSON representation
An internationalization library for your projects
- Host: GitHub
- URL: https://github.com/dsolartec/languages-rs
- Owner: dsolartec
- License: mit
- Created: 2021-03-26T20:52:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-13T02:23:01.000Z (over 3 years ago)
- Last Synced: 2024-10-07T16:04:24.550Z (about 1 month ago)
- Topics: accessibility, internationalization, localization, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 43 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# languages-rs ![Crates.io version][crates.io] ![CI workflow status][ci]
[crates.io]: https://img.shields.io/crates/v/languages-rs
[ci]: https://img.shields.io/github/workflow/status/danielsolartech/languages-rs/CIAn internationalization library for Rust.
## Installation
Use with JSON language files:
```toml
[dependencies]
languages-rs = { version = "0.2.0", features = ["with-json"] }
```Use with TOML language files:
```toml
[dependencies]
languages-rs = { version = "0.2.0", features = ["with-toml"] }
```## Basic Usage
`languages/en.json`
```json
{
"hello_world": "Hello world!"
}
````src/main.rs`
```rust
use languages_rs::{Config, Languages, load, Value};fn main() -> Result<()> {
let mut configuration: Config = Config::default().unwrap();
configuration.add_language("en").unwrap();// Load all default languages.
let texts: Languages = load(configuration).unwrap();// Get the English texts from `/languages/en.json`.
let texts_en: LanguagesTexts = texts.try_get_language("en").unwrap();// Get the `hello_world` text from English texts.
let en_hello_world: Value = texts_en.try_get_text("hello_world").unwrap();
assert!(en_hello_world.is_string());// Another alternative to get the `hello_world` text from English texts is:
let en_hello_world_2: Value = texts.try_get_text_from_language("en", "hello_world").unwrap();
assert!(en_hello_world_2.is_string());assert_eq!(en_hello_world, en_hello_world_2);
assert_eq!(en_hello_world.get_string(), en_hello_world_2.get_string());
}
```## Examples
- [json_files](./examples/json_files.rs) - Languages files with JSON.
```console
$ cargo run --example json_files --features "with-json"
```- [toml_files](./examples/toml_files.rs) - Languages files with TOML.
```console
$ cargo run --example toml_files --features "with-toml"
```## Testing
```console
$ cargo test
```## Authors
- [@daschdev](https://github.com/daschdev) - Initial project
## Changelog
View the lastest repository changes in the [CHANGELOG.md](./CHANGELOG.md) file.
## Copyright
License: MIT
Read file [LICENSE](./LICENSE) for more information.