Skip to main content

Crate fluent4rs

Crate fluent4rs 

Source
Expand description

§fluent4rs

MIT License Language Build Coverage Version

Site | GitHub | API | Coverage Report

A Fluent (language translation) resource file codec.

§Background

The fluent-syntax crate from Project Fluent parses Fluent FTL files. It provides a deserialisation only from the Resource level.

This crate:

  • enables conversion in both directions for any node in the syntax tree,
  • provides a syntax tree walker.

It has been written for lingora (a localization management program), and may be found to be useful outside of that context.

From version 2.3+, the underlying parser crate changed from pom to chumsky with a 92% performance improvement. The pom parser remains an option (via --no-default-features --features=parser-pom) if clients need to use it.

It is not intended to replace any aspects of the fluent-rs crate implemented by Project Fluent, and, for the majority of language translation needs, the reader is referred back to that crate.

Usagefluent4rsfluent-syntax
Programmatic inspection & editing of ftl files?
Language translation in a programxfluent

§Features

FeatureDescription
defaultDefault parser_chumskey,walker
parser_chumksyUse the chumksy parser; This feature and pom are mutually exclusive
parser_pomUse the pom parser; This feature and chumsky are mutually exclusive
hashAllow AST nodes to be hashed, for potential usages in HashMaps
serdeAllow AST nodes to be serialised / deserialised
traceInclude tracing to stderr in the DefaultVisitor implementation
walkerProvide AST walker and visitors

§Development

cargo test

§Benchmarking

cargo bench --no-default-features --features parser-pom --bench parser_bench -- --save-baseline pom
cargo bench --no-default-features --features parser-chumsky --bench parser_bench -- --baseline pom
parse_full_grammar_example
                        time:   [541.35 µs 543.99 µs 546.79 µs]
                        change: [−92.720% −92.660% −92.603%] (p = 0.00 < 0.05)
                        Performance has improved.

§AST Image View

Railroad

Relationships

Modules§

ast
Derived from Project Fluent fluent.ebnf
prelude
The prelude module – a convenient way to import the most commonly used types and traits when working with fluent4rs.