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

In-built currency formatting not working with ICU #50

Closed
Wildhoney opened this issue Jun 22, 2022 · 3 comments
Closed

In-built currency formatting not working with ICU #50

Wildhoney opened this issue Jun 22, 2022 · 3 comments

Comments

@Wildhoney
Copy link

Codesandbox: https://codesandbox.io/s/competent-wildflower-kpvrl5?file=/src/index.ts

When using ICU the built-in currency formatting doesn't seem to work at all — if you uncomment lines 2 and 4 you'll see that it breaks.

@adrai
Copy link
Member

adrai commented Jun 22, 2022

The built-in formatting is only for the i18next i18n format... but since you're using i18next-icu, this is a different i18n format and you need to check ICU instead...
i.e. "The price is: {price, number, ::currency/GBP}"

https://codesandbox.io/s/pedantic-poincare-jgnwzz

@adrai adrai closed this as completed Jun 22, 2022
@Wildhoney
Copy link
Author

Wildhoney commented Jun 22, 2022

I did check with i18next-icu and that ☝️ does work fine. I couldn't find a way in the docs to automatically add the currency symbol though for a custom formatter — in the in-built docs it seems to be a lot easier which is why I wanted to use that one.

I'm currently using the following custom formatter for price:

icu.addUserDefinedFormats({
    number: {
        PRICE_FORMAT: {
            minimumFractionDigits: 0,
            maximumFractionDigits: 2,
        },
    },
});

Is there a way to also add ::currency/GBP?

@jamuhl
Copy link
Member

jamuhl commented Jun 22, 2022

formats depend on IntlMessageFormat https://github.com/i18next/i18next-icu/blob/master/src/index.js#L66

as this basically just wraps that implementation of ICU messageformat - so you will have to look there what is possible or not

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

3 participants