Skip to content

Make fluent_number obey format specifiers for currencies #157

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

Closed
wants to merge 1 commit into from

Conversation

Sh4rK
Copy link

@Sh4rK Sh4rK commented Oct 1, 2020

Hi,

I just started to use fluent for python, and discovered that number format specifiers do not work for currencies.
Here's a small code snippet reproducing the issue:

from fluent.runtime import FluentBundle, FluentResource
from fluent.runtime.types import fluent_number

bundle = FluentBundle(["en"])
resource = FluentResource("amount = { $amount }")
bundle.add_resource(resource)

msg = bundle.get_message('amount')

amount = fluent_number(1, style="currency", currency="USD", minimumFractionDigits=0)
translated, errs = bundle.format_pattern(msg.value, {"amount": amount})
print(translated)  # Prints $1.00, expected $1.

Let me know if there's any issue with the patch!

@Pike
Copy link
Contributor

Pike commented Oct 2, 2020

Interesting topic. As we're talking currencies, @stasm, do you remember if we did anything about projectfluent/fluent.js#464 and the non-js impls?

As for this aspect of number formatting, I'm wary of exposing the number of digits to localizers for currencies. That doesn't sound like something that should be language specific. @stasm ?

Still, might be good to have a way for the programmer to control this.

@Sh4rK
Copy link
Author

Sh4rK commented Oct 2, 2020

To clarify why I opened this PR and give some input:

The project we're working on is primarily for Hungarian audiences, but we're trying to localize it to a few other languages now.

I tried currency formatting as that's something we will need, and my problem is that Hungarian Forints (HUF) get formatted with 2 decimal places. That's unusual and unnecessary for most (common) use cases, as there's no fractional HUF in common use (the smallest value coin currently in circulation is 5 HUF, that's worth less than 0.02 USD).

Now, there are some areas that actually use fractional HUF, for example banking and probably other forms of accounting, and the ISO standard that seems relevant here specifies 2 decimal places, but in everyday life (stores, restaurants, online shops, services, etc.) it never appears.

Because of the above two different use cases I think there should be a way to customize the formatting, even if this is not the right one.

@Sh4rK
Copy link
Author

Sh4rK commented Jun 27, 2022

Closing for lack of interest.

@Sh4rK Sh4rK closed this Jun 27, 2022
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.

2 participants