Name Description Size
ast
bin
lib.rs Fluent is a modern localization system designed to improve how software is translated. `fluent-syntax` is the lowest level component of the [Fluent Localization System](https://www.projectfluent.org). It exposes components necessary for parsing and tooling operations on Fluent Translation Lists ("FTL"). The crate provides a [`parser`] module which allows for parsing of an input string to an Abstract Syntax Tree defined in the [`ast`] module. The [`unicode`] module exposes a set of helper functions used to decode escaped unicode literals according to Fluent specification. # Example ``` use fluent_syntax::parser; use fluent_syntax::ast; let ftl = r#" hello-world = Hello World! "#; let resource = parser::parse(ftl) .expect("Failed to parse an FTL resource."); assert_eq!( resource.body[0], ast::Entry::Message( ast::Message { id: ast::Identifier { name: "hello-world" }, value: Some(ast::Pattern { elements: vec![ ast::PatternElement::TextElement { value: "Hello World!" }, ] }), attributes: vec![], comment: None, } ), ); ``` 1488
parser
unicode.rs A set of helper functions for unescaping Fluent unicode escape sequences. # Unicode Fluent supports UTF-8 in all FTL resources, but it also allows unicode sequences to be escaped in [`String Literals`](super::ast::InlineExpression::StringLiteral). Four byte sequences are encoded with `\u` and six byte sqeuences using `\U`. ## Example ``` use fluent_syntax::unicode::unescape_unicode_to_string; assert_eq!( unescape_unicode_to_string("Foo \\u5bd2 Bar"), "Foo 寒 Bar" ); assert_eq!( unescape_unicode_to_string("Foo \\U01F68A Bar"), "Foo 🚊 Bar" ); ``` # Other unescapes This also allows for a char `"` to be present inside an FTL string literal, and for `\` itself to be escaped. ## Example ``` use fluent_syntax::unicode::unescape_unicode_to_string; assert_eq!( unescape_unicode_to_string("Foo \\\" Bar"), "Foo \" Bar" ); assert_eq!( unescape_unicode_to_string("Foo \\\\ Bar"), "Foo \\ Bar" ); ``` 3907