Update README
This commit is contained in:
parent
b207dfc733
commit
da6225c32e
29
README.md
29
README.md
|
@ -1,20 +1,19 @@
|
||||||
# Locales
|
# Locales
|
||||||
|
|
||||||
![LICENSE](https://img.shields.io/crates/l/locales)
|
|
||||||
[![Crates.io Version](https://img.shields.io/crates/v/locales.svg)](https://crates.io/crates/locales)
|
[![Crates.io Version](https://img.shields.io/crates/v/locales.svg)](https://crates.io/crates/locales)
|
||||||
|
![LICENSE](https://img.shields.io/crates/l/locales)
|
||||||
[![Coverage Status](https://coveralls.io/repos/github/terry90/internationalization-rs/badge.svg?branch=master)](https://coveralls.io/github/terry90/internationalization-rs?branch=master)
|
[![Coverage Status](https://coveralls.io/repos/github/terry90/internationalization-rs/badge.svg?branch=master)](https://coveralls.io/github/terry90/internationalization-rs?branch=master)
|
||||||
[![Build Status](https://travis-ci.org/terry90/internationalization-rs.svg?branch=master)](https://travis-ci.org/terry90/internationalization-rs)
|
[![Build Status](https://travis-ci.org/terry90/internationalization-rs.svg?branch=master)](https://travis-ci.org/terry90/internationalization-rs)
|
||||||
|
|
||||||
An simple compile time i18n implementation in Rust.
|
A simple compile time i18n implementation in Rust.
|
||||||
It throws a compilation error if the translation key is not present, but since the `lang` argument is dynamic it will panic if the language has not been added for the matching key.
|
It throws a compilation error if the translation key is not present, but since the `lang` argument is dynamic it will panic if the language has not been added for the matching key.
|
||||||
|
|
||||||
> API documentation [https://crates.io/crates/locales](https://crates.io/crates/locales)
|
> API documentation [https://crates.io/crates/locales](https://crates.io/crates/locales)
|
||||||
|
|
||||||
## Usage
|
### Usage
|
||||||
|
|
||||||
Have a `locales/` folder somewhere in your app, root, src, anywhere. with `.json` files, nested in folders or not.
|
Have a `locales/` folder somewhere in your app, root, src, anywhere. with `.json` files, nested in folders or not.
|
||||||
It uses a glob pattern: `**/locales/**/*.json` to match your translation files.
|
It uses a glob pattern: `**/locales/**/*.json` to match your translation files.
|
||||||
|
|
||||||
the files must look like this:
|
the files must look like this:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
@ -35,7 +34,6 @@ the files must look like this:
|
||||||
```
|
```
|
||||||
|
|
||||||
Any number of languages can be added, but you should provide them for everything since it will panic if a language is not found when queried for a key.
|
Any number of languages can be added, but you should provide them for everything since it will panic if a language is not found when queried for a key.
|
||||||
|
|
||||||
In your app, just call the `t!` macro
|
In your app, just call the `t!` macro
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
@ -44,11 +42,23 @@ use locales::t;
|
||||||
fn main() {
|
fn main() {
|
||||||
let lang = "en";
|
let lang = "en";
|
||||||
let res = t!("err.not_allowed", lang);
|
let res = t!("err.not_allowed", lang);
|
||||||
|
|
||||||
assert_eq!("You are not allowed to do this", res);
|
assert_eq!("You are not allowed to do this", res);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If the key is missing, your code will not compile
|
||||||
|
|
||||||
|
```rust,compile_fail
|
||||||
|
use locales::t;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let lang = "en";
|
||||||
|
let res = t!("missing key", lang);
|
||||||
|
// Code will not compile
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
You can use interpolation, any number of argument is OK but you should note that they have to be sorted alphabetically.
|
You can use interpolation, any number of argument is OK but you should note that they have to be sorted alphabetically.
|
||||||
To use variables, call the `t!` macro like this:
|
To use variables, call the `t!` macro like this:
|
||||||
|
|
||||||
|
@ -63,7 +73,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
### Installation
|
||||||
|
|
||||||
Locales is available on [crates.io](https://crates.io/crates/locales), include it in your `Cargo.toml`:
|
Locales is available on [crates.io](https://crates.io/crates/locales), include it in your `Cargo.toml`:
|
||||||
|
|
||||||
|
@ -85,6 +95,9 @@ Or use the macro where you want to use it:
|
||||||
use locales::t;
|
use locales::t;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Note
|
### Note
|
||||||
|
|
||||||
Locales will not work if no `PWD` env var is set at compile time.
|
Locales will not work if no `PWD` env var is set at compile time.
|
||||||
|
It should work out of the box though
|
||||||
|
|
||||||
|
License: MIT/Apache-2.0
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
//! # Locales
|
|
||||||
|
|
||||||
//! [![Crates.io Version](https://img.shields.io/crates/v/locales.svg)](https://crates.io/crates/locales)
|
//! [![Crates.io Version](https://img.shields.io/crates/v/locales.svg)](https://crates.io/crates/locales)
|
||||||
//! ![LICENSE](https://img.shields.io/crates/l/locales)
|
//! ![LICENSE](https://img.shields.io/crates/l/locales)
|
||||||
//! [![Coverage Status](https://coveralls.io/repos/github/terry90/internationalization-rs/badge.svg?branch=master)](https://coveralls.io/github/terry90/internationalization-rs?branch=master)
|
//! [![Coverage Status](https://coveralls.io/repos/github/terry90/internationalization-rs/badge.svg?branch=master)](https://coveralls.io/github/terry90/internationalization-rs?branch=master)
|
||||||
//! [![Build Status](https://travis-ci.org/terry90/internationalization-rs.svg?branch=master)](https://travis-ci.org/terry90/internationalization-rs)
|
//! [![Build Status](https://travis-ci.org/terry90/internationalization-rs.svg?branch=master)](https://travis-ci.org/terry90/internationalization-rs)
|
||||||
//!
|
//!
|
||||||
//! An simple compile time i18n implementation in Rust.
|
//! A simple compile time i18n implementation in Rust.
|
||||||
//! It throws a compilation error if the translation key is not present, but since the `lang` argument is dynamic it will panic if the language has not been added for the matching key.
|
//! It throws a compilation error if the translation key is not present, but since the `lang` argument is dynamic it will panic if the language has not been added for the matching key.
|
||||||
|
|
||||||
//! > API documentation [https://crates.io/crates/locales](https://crates.io/crates/locales)
|
//! > API documentation [https://crates.io/crates/locales](https://crates.io/crates/locales)
|
||||||
|
@ -101,6 +99,7 @@
|
||||||
//! ## Note
|
//! ## Note
|
||||||
|
|
||||||
//! Locales will not work if no `PWD` env var is set at compile time.
|
//! Locales will not work if no `PWD` env var is set at compile time.
|
||||||
|
//! It should work out of the box though
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
|
include!(concat!(env!("OUT_DIR"), "/i18n.rs"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue