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
//! Fluent is a localization system designed to improve how software is translated. //! //! The Rust implementation provides the low level components for syntax operations, like parser //! and AST, and the core localization struct - `FluentBundle`. //! //! `FluentBundle` is the low level container for storing and formatting localization messages. It //! is expected that implementations will build on top of it by providing language negotiation //! between user requested languages and available resources and I/O for loading selected //! resources. //! //! # Example //! //! ``` //! use fluent_bundle::{FluentBundle, FluentValue, FluentResource}; //! use std::collections::HashMap; //! //! let ftl_string = String::from(" //! hello-world = Hello, world! //! intro = Welcome, { $name }. //! "); //! let res = FluentResource::try_new(ftl_string) //! .expect("Could not parse an FTL string."); //! //! let mut bundle = FluentBundle::new(&["en-US"]); //! //! bundle //! .add_resource(&res) //! .expect("Failed to add FTL resources to the bundle."); //! //! let (value, _) = bundle //! .format("hello-world", None) //! .expect("Failed to format a message."); //! //! assert_eq!(&value, "Hello, world!"); //! //! let mut args = HashMap::new(); //! args.insert("name", FluentValue::from("John")); //! //! let (value, _) = bundle //! .format("intro", Some(&args)) //! .expect("Failed to format a message."); //! //! assert_eq!(value, "Welcome, John."); //! ``` #[macro_use] extern crate rental; #[macro_use] extern crate failure_derive; pub mod bundle; pub mod entry; pub mod errors; pub mod resolve; pub mod resource; pub mod types; pub use bundle::FluentBundle; pub use resource::FluentResource; pub use types::FluentValue;