projectfluent / fluent-rs

Rust implementation of Project Fluent
https://projectfluent.org
Apache License 2.0
1.08k stars 97 forks source link

Cannot use built-in functions #313

Closed lynn2910 closed 4 months ago

lynn2910 commented 1 year ago

Hello, i have this fluent content:

server_info_desc =   > 🏷️ **Quelques statistiques :**
  {"** **"}
  `{ NUMBER($emojis) }` emojis
  `{ NUMBER($stickers) }` stickers
  `{ NUMBER($threads) }` threads
  `{ NUMBER($categories) }` categories

But, when i run it, the text displayed is:

⁨{NUMBER()}⁩ emojis
⁨{NUMBER()}⁩ stickers
⁨{NUMBER()}⁩ threads
⁨{NUMBER()}⁩ categories

So, at first, I was thinking that i wasn't using the good names or syntax, but everything work properly on web playground, and, this is how I'm declaring all arguments:

            let mut fluent_args = FluentArgs::new();
            {
                fluent_args.set("emojis", emojis_nb);
                fluent_args.set("stickers", stickers_nb);
                fluent_args.set("threads", threads);
                fluent_args.set("categories", categories);
            }

Because of all that, the only option is that I missed something when formatting the message. I use this function:

  pub fn get(&self, lang: &String, id: &str, args: Option<&FluentArgs<'_>>) -> String {
    if let Some(bundle) = self.lib.get(lang) {
      let msg = bundle.get_message(id);
      if let Some(m) = msg {
        if let Some(value) = m.value() {
          let mut err = vec![];
          bundle.format_pattern(value, args, &mut err).to_string()
        } else {
          NO_VALUE.clone().to_string()
        }
      } else {
        NO_MESSAGE.clone().to_string()
      }
    } else {
      NO_LANG.clone().to_string()
    }
  }

Anyone know why this isn't working properly ?

kellpossible commented 1 year ago

Perhaps they were never implemented as per https://github.com/projectfluent/fluent-rs/issues/19#issuecomment-466160940 ?

alerque commented 4 months ago

This is definitely a valid issue, built in types were never implemented so of course they could not be used.

That being said I think I'm going to close this issue because we have more specific ones for tracking each implementation. Besides #19, an older duplicate of the general issue, a NUMBER() function is in progress in #353 that can be tracked there. Additionally a specific issue for DATETIME() is at #181.