= i18n_message Rizzen Yazston

== Message system

The i18n_message crate contains the messaging system.

A message system that connects to a string data store, to obtain strings for the specified language using a string identifier, and formatting the string to replace any placeholders within the string with provided values.

The message is capable of caching retrieved strings that are prepared for placeholder replacement, thus can be reused without the need to parse the string for placeholders.

The message system makes use of all the other component crates that make up the i18n project. Ideally one only needs to use the meta crate i18n, as it includes all the crates including this i18n_message crate.

== Acknowledgement

Stefano Angeleri for advice on various design aspects of implementing the components of the internationalisation project, and also providing the Italian translation of error message strings.

== Cargo.toml

``` [dependencies] i18nmessage-rizzen-yazston = "0.6.1" i18nicu-rizzen-yazston = "0.6.1" i18nlexer-rizzen-yazston = "0.6.1" # Needed for Token, TokenType i18npattern-rizzen-yazston = "0.6.1" i18nprovider-rizzen-yazston = "0.6.1" i18nprovidersqlite3-rizzen-yazston = "0.6.1" i18nutility-rizzen-yazston = "0.6.1" tree-rizzen-yazston = "0.4.0" icu_provider = "1.2.0"

These are required for the DataProvider.

icuproperties = "1.2.0" icusegmenter = "1.2.0" icuplurals = "1.2.0" icudecimal = "1.2.0" icucalendar = "1.2.0" icudatetime = "1.2.0"

This is required for the DataProvider.

[dependencies.fixed_decimal] version = "0.5.3"

Needed for floating point support.

features = [ "ryu" ] ```

== Examples

``` use i18nicu::IcuDataProvider; use i18nregistry::LanguageTagRegistry; use i18nprovidersqlite3::ProviderSqlite3; use i18npattern::{PlaceholderValue, CommandRegistry}; use i18nmessage::Message; use icutestdata::buffer; use icuprovider::serde::AsDeserializingBufferProvider; use std::collections::HashMap; use std::rc::Rc; use std::error::Error;

fn message() -> Result<(), Box> { let bufferprovider = buffer(); let dataprovider = bufferprovider.asdeserializing(); let icudataprovider = Rc::new( IcuDataProvider::trynew( &dataprovider )? ); let languagetagregistry = Rc::new( LanguageTagRegistry::new() ); let lstringprovider = ProviderSqlite3::trynew( "./i18n/", &languagetagregistry )?; let commandregistry = Rc::new( CommandRegistry::new() ); let messagesystem = Message::trynew( &icudataprovider, &languagetagregistry, &lstringprovider, &commandregistry, true, true )?; let mut values = HashMap::::new(); values.insert( "identifier".tostring(), PlaceholderValue::String( "i18nmessage/stringnotfound".tostring() ) ); values.insert( "languagetag".tostring(), PlaceholderValue::String( "en-ZA".tostring() ) ); values.insert( "fallback".tostring(), PlaceholderValue::String( "true".tostring() ) ); let lstring = messagesystem.format( "i18nmessage/stringnotfound", &values, &languagetagregistry.getlanguagetag( "en-ZA" ).unwrap(), None, None )?; asserteq!( lstring.asstr(), "No string was found for identifier ‘i18nmessage/stringnotfound’ and language tag ‘en-ZA’. Fallback used: True.", "Check placeholder values." ); Ok( () ) } ```