1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109

//! # r_i18n
//! An i18n implementation in Rust. 

//! [![Build Status](https://travis-ci.com/WebD-EG/r_i18n.svg?branch=master)](https://travis-ci.com/WebD-EG/r_i18n)

//! > API documentation [https://crates.io/crates/r_i18n](https://crates.io/crates/r_i18n)

//! **Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*

//! - [r_i18n](#r_i18n)
//!   - [Installation](#installation)
//!   - [Usage](#usage)
//!     - [Configuration](#configuration)
//!     - [Example](#example)
//! - [Contribution guide](#contribution-guide)



//! ## Installation
//! To install the library, you have to put this line into your **Cargo.toml** file.
//! ```toml
//! [dependencies]
//! r_i18n = "version number"
//! ```

//! ## Usage

//! ### Configuration
//! First, create the configuration with the directory that contains your translations files and your languages.
//! ```no-run
//! extern crate r_i18n;
//! use r_i18n::I18nConfig;

//! fn main() {
//!     let config =  I18nConfig{locales: &["en", "fr", "es"], directory: "translations"};
//! }
//! ```
//! Then, load the configuration:
//! ```no-run
//! extern crate r_i18n;
//! use r_i18n::I18n;

//! fn main() {
//!     let config: I18nConfig =  I18nConfig{locales: &["en", "fr", "es"], directory: "translations"};
//!     let r_i18n: I18n = I18n::configure(&config);
//! }
//! ```
//! With this example, you will need to have a **en.json**, **fr.json** and **es.json** inside the /translations directory. Each file should looks like that:
//! ```json
//! {
//!     "keyword": "value"
//! }
//! ```
//! ### Example
//! I have a en.json file that looks like that:
//! ```json
//! {
//!     "introduction": "Hello, my name is WebD"
//! }
//! ```

//! Then, in my main.rs

//! ```no-run
//! extern crate r_i18n;
//! use r_i18n::I18n;
//! use r_i18n::I18nConfig;

//! fn main() {
//!     let config: I18nConfig =  I18nConfig{locales: &["en", "fr", "es"], directory: "translations"};
//!     let r_i18n: I18n = I18n::configure(&config);
//!     // by default, the current language will be the first element of the locales array. You can do like that if you want to set the language:
//!     // r_i18n.set_current_lang("fr");
//!     r_i18n.t("introduction"); // output should be "Hello, my name is WebD"
//! }
//! ```

//! Now, I have a fr.json file that looks like that:
//! ```json
//! {
//!     "introduction": "Bonjour, mon nom est WebD"
//! }
//! ```

//! If I set the current language to french:
//! ```no-run
//! extern crate r_i18n;
//! use r_i18n::I18n;

//! fn main() {
//!     let config: I18nConfig =  I18nConfig{locales: &["en", "fr", "es"], directory: "translations"};
//!     let r_i18n: I18n = I18n::configure(&config);
//!     r_i18n.set_current_lang("fr");
//!     r_i18n.t("introduction"); // output should be "Bonjour, mon nom est WebD
//! }
//! ```

//! # Contribution guide
//! 1. Fork and Clone the repository
//! 2. Create your own branch
//! 3. Start Coding!
//! 4. Make a pull request when you're done :)

extern crate json;

pub mod i18n;
pub use i18n::I18n;
pub use i18n::I18nConfig;