Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FluentNumber to use ICU4X #269

Open
2 of 9 tasks
juliancoffee opened this issue Aug 9, 2022 · 7 comments
Open
2 of 9 tasks

Update FluentNumber to use ICU4X #269

juliancoffee opened this issue Aug 9, 2022 · 7 comments
Assignees
Labels
help wanted We need help making decisions or writing PRs for this. icu4x Migrate example components to use icu4x instead of custom stubbed out components.

Comments

@juliancoffee
Copy link
Contributor

juliancoffee commented Aug 9, 2022

Update (from @gregtatum): This bug is now about about using ICU4X's number formatter to back FluentNumber.


It seems that fluent-rs can parse options for numbers, but not use them.
Looking at FluentNumber::as_string(), the only option that gets used is minimum fraction digits.

    pub fn as_string(&self) -> Cow<'static, str> {
        let mut val = self.value.to_string();
        if let Some(minfd) = self.options.minimum_fraction_digits {
            if let Some(pos) = val.find('.') {
                let frac_num = val.len() - pos - 1;
                let missing = if frac_num > minfd {
                    0
                } else {
                    minfd - frac_num
                };
                val = format!("{}{}", val, "0".repeat(missing));
            } else {
                val = format!("{}.{}", val, "0".repeat(minfd));
            }
        }
        val.into()
    }

So, things to implement:

  • Percent formatting
  • Currency formatting
  • Decimal formatting (implicitly assumed, I guess)
  • use_grouping
  • minimum_integer_digits
  • minimum_fraction_digits
  • maximum_fraction_digits
  • minimum_significant_digits
  • maximum_significant_digits
@juliancoffee
Copy link
Contributor Author

@zbraniecki
I thought about implementing percentage formatting, but I'm a bit worried about language-dependent formatting, do you have any advice on how to do it?

@zbraniecki
Copy link
Collaborator

I'd wait for ICU4X NumberFormatter, we have scaffolding for it in https://unicode-org.github.io/icu4x-docs/doc/fixed_decimal/index.html for some aspects, and unicode-org/icu4x#1441 for others.

Maybe you'd like to help with that? :)

@juliancoffee
Copy link
Contributor Author

I'd wait for ICU4X NumberFormatter, we have scaffolding for it in https://unicode-org.github.io/icu4x-docs/doc/fixed_decimal/index.html for some aspects, and unicode-org/icu4x#1441 for others.

Maybe you'd like to help with that? :)

Yeah, I was looking at that a bit. What are the approximate steps for working on that?

@zbraniecki
Copy link
Collaborator

What are the approximate steps for working on that?

You can go to issue #1441 and say you'd like to take it and ask for mentorship. Someone from our team will mentor you through that.

If you prefer some other feature of Number Formatter you can ask here unicode-org/icu4x#275 and we'll help you carve out correct API to work on.

The concept in ICU4X is to divide what JS knows as NumberFormat into a tree of more specific and smaller formatters.

@gregtatum
Copy link
Member

In Firefox we are using ICU4C to do this, but the examples in fluent-rs should be backed by ICU4X's number formatter. I'll update this issue to say as much.

@gregtatum gregtatum added help wanted We need help making decisions or writing PRs for this. icu4x Migrate example components to use icu4x instead of custom stubbed out components. labels Nov 7, 2022
@gregtatum gregtatum changed the title Number formatting isn't properly implemented Update FluentNumber to use ICU4X Nov 7, 2022
@alerque
Copy link
Collaborator

alerque commented May 6, 2024

I believe this work is already in progress and should be addressed as part of #335. Also of note #303 along the way. Also relevant is #353 which touches on these implementations.

@JasperDeSutter
Copy link
Contributor

I'd be happy to open up #303 again, I can try and see if the approach taken for data providers in #335 works for number formatting as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We need help making decisions or writing PRs for this. icu4x Migrate example components to use icu4x instead of custom stubbed out components.
Projects
None yet
Development

No branches or pull requests

6 participants