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

"amount" template filter ignores LC_NUMERIC environment variable #66

Closed
BredoGen opened this issue Sep 14, 2018 · 6 comments
Closed

"amount" template filter ignores LC_NUMERIC environment variable #66

BredoGen opened this issue Sep 14, 2018 · 6 comments

Comments

@BredoGen
Copy link

Hi.

There is a problem using Saleor/django-prices in case with some default locales:
e.g:

LANGUAGE_CODE=ru
DEFAULT_CURRENCY=USD

Usage:
{{ price|amount:'html' }}
Output: 11,49 $

It is not valid output for USD currency (even for RU locale). The valid one is classic $11.49

Reason:
"|amount" template filter forces currency format by passing the current language to Babel as locale (see templatetags/prices_i18n.py:42).

Babel supports overriding numeric locale via LC_NUMERIC env.

It will be very useful if get_locale_data() in prices_i18n.py will be checking this env before passing currency locale to Babel.

@patrys
Copy link
Contributor

patrys commented Sep 14, 2018

It is a valid output for both ru and ru-RU locales. Comma is used as a decimal separator and currency code is properly placed as a suffix.

I've also verified that with the Unicode CLDR database. Javascript behaves the same:

console.log((11.49).toLocaleString("ru", {style: "currency", currency: "USD"}))
// "11,49 $"

@BredoGen
Copy link
Author

BredoGen commented Sep 14, 2018

It is a valid output for both ru and ru-RU locales. Comma is used as a decimal separator and currency code is properly placed as a suffix.

Sorry, yes, both versions are valid for Russian. But $ as prefix is more common for prices in e-commerce.

Introducing optional LC_NUMERIC env will give a chance to use different LANGUAGE and NUMERIC locale for such cases (Babel already uses it in format_currency() method).

@patrys
Copy link
Contributor

patrys commented Sep 14, 2018

Wouldn't using LC_NUMERIC override the format for all languages? There are systems where that variable is exported by the OS which would force the user to explicitly override it which I'm sure would result in bugs being filed against Saleor. What about the decimal point character being different?

@BredoGen
Copy link
Author

BredoGen commented Sep 14, 2018

Wouldn't using LC_NUMERIC override the format for all languages? There are systems where that variable is exported by the OS which would force the user to explicitly override it which I'm sure would result in bugs being filed against Saleor.

You're right. If LC_NUMERIC will be exported by the OS - it'll break multi-language currency localization setup.

What about the decimal point character being different?

Using dot as decimal separator for USD prices in Russian is OK and even more common. Everyone is used to see USD prices in English formatting in e-commerce.

Comma as separator and suffix notation is more common for rubles prices: 10,000 RUB.

So, there is no easy solution to include in core.

It's better for me to override "amount" filter implementing my custom logic there (maybe via dict in settings which will override numeric locale for some languages). Now I realize that this feature is redundant for core functionality.

Sorry for erroneous report

@patrys
Copy link
Contributor

patrys commented Sep 14, 2018

What if there was a way to override certain settings on a per-locale setting? For example to say that you want to use ¤ #,##0.00 for US dollars in Russian.

@BredoGen
Copy link
Author

What if there was a way to override certain settings on a per-locale setting? For example to say that you want to use ¤ #,##0.00 for US dollars in Russian.

It will be great feature and it'll completely resolve the problem

@BredoGen BredoGen closed this as completed Jul 9, 2024
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

No branches or pull requests

2 participants