feat(currency): Add accounting formatting support to CurrencyFormatter<Compact>#8187
Open
younies wants to merge 2 commits into
Open
feat(currency): Add accounting formatting support to CurrencyFormatter<Compact>#8187younies wants to merge 2 commits into
younies wants to merge 2 commits into
Conversation
… and simplify options This commit modernizes compact currency formatting in ICU4X by: 1. Architecture Migration: Migrating CompactCurrencyFormatter to adopt the generic CurrencyFormatter<Compact> design with try_new_short and try_new_narrow constructors (where currency is bound at construction time). 2. Options Simplification: Removing CurrencyFormatterOptions from options.rs and replacing it with a direct pub(crate) width: Width field across CurrencyFormatter<V>, as width is now determined at construction time. 3. Pattern Gluing: In format_fixed_decimal, we use name_and_pattern from CurrencyEssentialsV1 (which resolves standard vs standard_alpha_next_to_number patterns), format the number via compact decimal (compact_data), and glue the compact number with the currency symbol. TAG=agy CONV=c033380d-144b-4f6b-b091-b5c89c4f80a1
…r<Compact> This commit implements accounting currency formatting (e.g. using parentheses for negative values in locales like en-US) for compact currency formatting (`CurrencyFormatter<Compact>`). - Restores `CurrencyFormatterOptions` and `CurrencyUsage` (`Standard`, `Accounting`) in `options.rs`. - Adds `options: CurrencyFormatterOptions` to `CurrencyFormatter<Compact>` constructors (`try_new_short` / `try_new_narrow`). - Resolves accounting positive and negative patterns from `CurrencyEssentials` in `format_fixed_decimal`. - Passes `Sign::None` to `DecimalFormatter::format_sign` when an accounting negative pattern has already formatted the negative sign. - Keeps standard `Decimal` currency formatting untouched to ensure a clean merge with upstream changes. - Adds comprehensive unit tests for accounting compact currency formatting. Fixes unicode-org#8185 TAG=agy CONV=c033380d-144b-4f6b-b091-b5c89c4f80a1
09475ef to
c5c216c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements accounting currency formatting support (e.g., formatting negative monetary values in parentheses like
($12K)inen-US) for compact currency formatting (CurrencyFormatter<Compact>).This PR is stacked on top of #8182 (
compact-currency-formatting).Changelog
Restore
CurrencyFormatterOptions&CurrencyUsage:CurrencyFormatterOptionsinoptions.rscontainingpub usage: CurrencyUsage.pub enum CurrencyUsage { #[default] Standard, Accounting }. (Note:Cashis left out of this PR intentionally so that this stack merges cleanly with feat(currency): Add accounting formatting and relax constructor validation #8177 when both reach upstreammain).Accounting Pattern Resolution in
CurrencyFormatter<Compact>:try_new_short/try_new_narrow(and unstable/buffer counterparts) onCurrencyFormatter<Compact>to acceptoptions: CurrencyFormatterOptions.format_fixed_decimal, checksself.options.usage == CurrencyUsage::Accounting. When formatting a negative number, queriesaccounting_negative_pattern()(oraccounting_alpha_next_to_number_negative_pattern()) fromCurrencyEssentialsV1, falling back cleanly to standard negative patterns if no accounting pattern is defined for the locale.Sign::NonetoDecimalFormatter::format_signso it does not prepend a redundant minus sign (preventing-($12K)).Zero Conflicts with Standard Decimal Formatting (feat(currency): Add accounting formatting and relax constructor validation #8177):
Decimalcurrency formatting (format.rsandformatter.rsconstructor signatures) is kept 100% untouched to avoid merge conflicts with feat(currency): Add accounting formatting and relax constructor validation #8177.Testing:
compact_format.rsto passDefault::default().test_accountingunit test incompact_format.rsverifying thatCurrencyUsage::Accountingformats-12345.67as($12K)inen-US.Verification
cargo clippy -p icu_experimental --no-depspassed cleanly.cargo fmt --all -- --checkpassed cleanly.cargo test -p icu_experimentalpassed (all 49 unit tests and 40 doctests).Fixes #8185