fluent-fmt

Crates.iofluent-fmt
lib.rsfluent-fmt
version0.1.1
sourcesrc
created_at2021-03-28 11:06:09.217348
updated_at2021-03-29 07:15:15.187454
descriptionConfigurable formatter for fluent `ftl` file
homepage
repositoryhttps://github.com/doki-land/doki-system-fluent
max_upload_size
id374624
size11,051
SasakiSaki (oovm)

documentation

README

Doki System Fluent

Doki use fluent for localization,

// in notedown
// config.language is current language
\locale::SOME_FILED("title", lang=config.language)

// in template
<locale::SOME_FILED default="title" lang=config.language/>

Here are some auxiliary libraries:

  • fluent_fmt: Configurable formatter for fluent ftl file.
  • fluent_missing: Compare and find missing fields in a language.

Fluent Formatter

Cli

call with doki locale fmt

Lib

use fluent_fmt::FluentFormatter;
use fluent_syntax::parser::parse;

#[test]
fn parsing() {
    let mut ctx = FluentFormatter::default();
    let ftl = r#"
### Resource Level Comment
###   * Resource Level Comment2
###   * Resource Level Comment3

# This is a message comment
time-elapsed = Time elapsed: { 
    NUMBER($duration, maximumFractionDigits: 0) 
        }s.
    .placeholder = email@example.com
    .aria-label = Login input value
    .title = Type your login email

# Complex things are possible.
shared-photos =
    {$userName} {$photoCount ->
        [one] added a new photo
       *[other] added {
            $photoCount
        } new photos
    } to {
$userGender ->
        [male] his stream
        [female] her stream
       *[other] their stream
    }.
"#;
    let out = parse(ftl).unwrap();
    // println!("{:#?}", out);
    println!("{}", ctx.pretty_print(out).unwrap())
}

Fluent Missing

Cli

call with doki locale mis

Lib

Commit count: 0

cargo fmt