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

Currency Formatter #1441

Open
sffc opened this issue Dec 22, 2021 · 4 comments
Open

Currency Formatter #1441

sffc opened this issue Dec 22, 2021 · 4 comments
Assignees
Labels
C-numbers Component: Numbers, units, currencies S-epic Size: Major project (create smaller child issues) T-core Type: Required functionality U-ecma402 User: ECMA-402 compatibility

Comments

@sffc
Copy link
Member

sffc commented Dec 22, 2021

This issue is to track all work needed for currency formatting in ICU4X.

Some high-level design notes:

  • We want to build on top of FixedDecimal and FixedDecimalFormat
  • We should be as modular as possible
  • We should build this system to be extensible to future features such as Compact Currency ("$1M") and Global Currency ("$1 USD")
  • The currency influences the rounding of the FixedDecimal, so this needs to be built into the API somehow
  • I think it probably makes sense to make a class called CurrencyFormat, but we may want to explore other alternatives

Links:

@sffc sffc added T-core Type: Required functionality C-numbers Component: Numbers, units, currencies S-epic Size: Major project (create smaller child issues) labels Dec 22, 2021
@sffc sffc added this to the ICU4X 0.6 milestone Dec 22, 2021
@robertbastian robertbastian modified the milestones: ICU4X 0.6, ICU4X 1.1 Apr 1, 2022
@sffc sffc assigned eggrobin and unassigned robertbastian May 25, 2022
@sffc
Copy link
Member Author

sffc commented May 25, 2022

Re-assigning the macro issue for currency formatting to @eggrobin for the 1.1 milestone. This is Q3/Q4 material.

@sffc sffc assigned younies and unassigned eggrobin Dec 14, 2022
@sffc sffc added the discuss-priority Discuss at the next ICU4X meeting label Dec 14, 2022
@sffc
Copy link
Member Author

sffc commented Dec 14, 2022

We still need to establish the data model for currency formatter.

There are two aspects of a data model:

  1. What data is stored in what keys and what locales?
  2. Within each individual key, what is the zerovec structure?

There are many ways to do this, all with pros and cons.

@younies @Manishearth

@sffc
Copy link
Member Author

sffc commented Dec 15, 2022

Discussion:

  • @robertbastian - Can we realistically put the currency in the key? There are new currencies all the time.
  • @robertbastian - On commerce sites, you don't control at build time which currency to load.
  • @sffc - For apps that require one currency at a time, we can do auto-slicing if the call sites are CurrencyFormatter::<USD>. Not sure if currencies are more like calendars (which are in the key) or collations (which are in the locale).
  • @robertbastian - I think making this code-driven is a bad i18n practice.
  • @sffc - There are lots of interesting way to slice currency data. Maybe we can drop display names that are for rarely used currencies. Perhaps we want to give that power to datagen, not locking us into the code approach.
  • @Manishearth - Over time we're going to need configurable datagen. So this seems like a feature that is good to have. I'm a bit sad if this isn't automatic, but it's probably the right decision to make it variable.
  • @echeran - We shouldn't create extra sophistication until we have solid justification that static typing is a common, priority use case that justifies the cost.
  • @sffc - I've heard a lot of solid arguments about making this data-driven rather than static-type-driven.
  • @robertbastian - We should use this opportunity to improve datagen for other things as well, like calendars
  • @younies - I think for units, we're not going to be able to use static keys. It would be nice for currency and measurement units to be similar in this aspect.
  • @Manishearth - Not everyone is ready for a library update to add a currency.

Conclusion: make the set of currencies data-driven.

@sffc sffc removed the discuss-priority Discuss at the next ICU4X meeting label Dec 15, 2022
@sffc
Copy link
Member Author

sffc commented Dec 16, 2022

A few ways to encode it at lookup time:

  1. Use a Unicode extension keyword: ar-u-cu-usd
  2. Use a private use subtag: en-x-eur
  3. Add an extra path segment: en/eur or eur/en

Reasons to favor option 3: This shouldn't be controllable by the user locale, so option 1 is out. Option 2 is a bit tricky/confusing if the user locale has a -x and we drop it.

To set option 3, we add a setter to DataLocale that sets the separate metadata field. Suggested naming:

  • set_prefix
  • set_content
  • set_content_locale
  • set_content_type
  • set_content_version
  • set_content_style
  • set_runtime
  • set_style
  • set_keyword
  • set_version
  • set_kind
  • set_criterion
  • set_property
  • set_field
  • set_extra_field
  • set_aux
  • set_auxiliary
  • set_aux_field
  • set_auxiliary_field
  • set_auxiliary_key
  • set_intermediate
  • set_intermediate_key

Tentative decision: set_auxiliary_key. Make it hidden initially.

Additional thought from @robertbastian: en-NZ should fall back to en-ZZ so that we don't get US currency symbols implicitly.

sffc added a commit that referenced this issue Apr 2, 2024
…at (#4750)

Cleans up the currency formatter code a bit.

Part of #1441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-numbers Component: Numbers, units, currencies S-epic Size: Major project (create smaller child issues) T-core Type: Required functionality U-ecma402 User: ECMA-402 compatibility
Projects
None yet
Development

No branches or pull requests

5 participants