#icu4x #localization #ast #string-formatting #syntax-tree #data-provider

i18n_pattern-rizzen-yazston

The i18n_pattern crate of the Internationalisation project

3 releases (breaking)

0.8.0 Feb 3, 2024
0.7.0 Dec 18, 2023
0.6.1 Jul 6, 2023

#397 in Internationalization (i18n)

Download history 3/week @ 2024-09-23

55 downloads per month
Used in i18n_message-rizzen-yazst…

BSD-3-Clause

180KB
2.5K SLoC

i18n_pattern

Rizzen Yazston

Pattern parser and formatter

The parser handles the parsing of string tokens into an Abstract Syntax Tree (AST), checking the grammar of patterns is valid. The parser only does the syntactic analysis of the supplied Token vector.

The formatter takes the AST that was generated by the parser and constructs a string template for values to be substituted into. The formatter also does the semantic analysis of the grammar. Once a string template has been constructed, it can be used multiple times by simply supplying new placeholder values when executing the format() method. Depending on the placeholder type of the pattern, a suitable selection of the available data types can be used, these include the basic String, integers, unsigned integers and floats. In addition to these special ICU4X types are supported such as FixedDecimal, Date, Time and DateTime structs.

See pattern strings.asciidoc in docs of pattern crate for the pattern formatting specification.

Features

Available features for i18n_icu crate:

  • compiled_data (Preferred): Enable the compiled_data feature on i18n_icu. Allow for the internal data of the various ICU4X components.

  • blob: Enable the blob feature on i18n_icu. Allow for instances of BlobDataProvider to be used various ICU4X components that supports {BufferProvider}BufferProvider.

  • fs: Enable the fs feature on i18n_icu. Allow for instances of FsDataProvider to be used various ICU4X components that supports BufferProvider.

  • sync: Allow for rust's concurrency capabilities to be used. Use of Arc and Mutex instead Rc and RefCell.

  • log: To provide some logging information.

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.

Dependencies

~7MB
~121K SLoC