2 releases

0.1.1 Mar 29, 2021
0.1.0 Mar 28, 2021

#196 in Internationalization (i18n)

MPL-2.0 license

12KB
287 lines

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

Dependencies

~0.4–1.5MB
~32K SLoC