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

Implement LongCurrencyFormatter for Long Currency Formatting #5351

Merged
merged 18 commits into from
Aug 26, 2024

Conversation

younies
Copy link
Member

@younies younies commented Aug 9, 2024

Task:
In this PR, implement LongCurrencyFormatter which handles formatting currencies in long formats.

Related issues:
#5353

@younies younies changed the title Create & Implement LongCurrencyFormatter Implement LongCurrencyFormatter for Long Currency Formatting Aug 9, 2024
@younies younies marked this pull request as ready for review August 9, 2024 14:48
components/experimental/src/dimension/currency/format.rs Outdated Show resolved Hide resolved
components/experimental/src/dimension/currency/format.rs Outdated Show resolved Hide resolved
let pattern = patterns
.get(&pattern_count)
.or_else(|| patterns.get(&PatternCount::Other))
.ok_or(core::fmt::Error)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmmm

in this case we have two options,

  1. to not return error at all and use default pattern
  2. move this logic to format_fixed_decimal method

I prefer option 2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So PatternCount::Other should always exist, so it would make sense to not have it in the map, but put it as a required field on the struct. You'd have

other: Pattern,
addtional_cases: ZeroMap<PatternCount, Pattern>,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, other must be present. I added this condition to the datagen`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this was represented in the type system, instead of with a trust-me-unwrap.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point: #5374 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

@younies younies requested a review from robertbastian August 13, 2024 12:41
Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@younies younies requested a review from a team as a code owner August 15, 2024 09:32
currency/patterns@1, blo, 82B, da128faf13fad0d5
currency/patterns@1, ceb, 72B, db7c7c84fecaf3d0
currency/patterns@1, es-GT, 72B, -> ceb
currency/patterns@1, ja, 61B, 9af35aad6ebc7d70
currency/patterns@1, my, 62B, 86cee97085536d8b
currency/patterns@1, ro, 85B, 629b2b7dcea97875
currency/patterns@1, sd, 48B, 3a6d9523170345d0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be a CLDR bug (missing Other), can you file an issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already filed this issue: #5374. I want to discuss it with @sffc today to ensure that it is a CLDR issue before filing it. If it is a CLDR issue, we need to decide what to do in the meantime. We can use the default {0} {1} or the pattern from en-US.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let pattern = patterns
.get(&pattern_count)
.or_else(|| patterns.get(&PatternCount::Other))
.ok_or(core::fmt::Error)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this was represented in the type system, instead of with a trust-me-unwrap.

@younies younies requested a review from robertbastian August 15, 2024 13:50
Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@younies younies requested a review from robertbastian August 22, 2024 20:15
@younies younies closed this Aug 22, 2024
@younies younies reopened this Aug 22, 2024
@younies younies requested a review from kartva August 23, 2024 12:42
Copy link
Member

@kartva kartva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing approving

Comment on lines +33 to +38
let plural_category = self.plural_rules.category_for(self.value);
let display_name = self.extended.display_names.get_str(plural_category);
let pattern = self.patterns.patterns.get_pattern(plural_category);
let formatted_value = self.fixed_decimal_formatter.format(self.value);
let interpolated = pattern.interpolate((formatted_value, display_name));
interpolated.write_to(sink)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: good code here, just loading things and interpolating them. No allocations.

@younies younies merged commit f06f048 into unicode-org:main Aug 26, 2024
28 checks passed
@younies younies deleted the long-currency-formatter branch August 26, 2024 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants