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

Use different locale for number and date formatting than current locale #2053

Open
3 tasks done
MickL opened this issue Dec 21, 2024 · 5 comments
Open
3 tasks done

Use different locale for number and date formatting than current locale #2053

MickL opened this issue Dec 21, 2024 · 5 comments
Labels
Status: Proposal Request for comments

Comments

@MickL
Copy link

MickL commented Dec 21, 2024

Clear and concise description of the problem

  • The common number format in the EU, at least for the countries I know, is 1.000,00 €
  • I have a website translated in German, French and Spanish as well as an English version for all other countries
  • For the English version I use the locale en
  • The format now is incorrectly €1,000.00 instead of 1.000,00 €

Suggested solution

The problem is that even when trying to format 'en' with Intl.NumberFormat to a European format it is not possible. So the only solution I could imagine is to be able to set a different locale for translations and for number formatting.

Alternative

No response

Additional context

No response

Validations

@MickL MickL added the Status: Proposal Request for comments label Dec 21, 2024
@MickL
Copy link
Author

MickL commented Feb 25, 2025

Did anyone had a chance to look at this? It is kinda crucial that it is impossible to format a currency like this: 1.000,00 € for locale en.

Also I create another feature request because each locale creates tons of duplicate code which might be related if doing a refactoring: #2054

@BobbieGoede @kazupon @babu-ch

@BobbieGoede
Copy link
Member

The problem is that even when trying to format 'en' with Intl.NumberFormat to a European format it is not possible.

In The Netherlands (and other Dutch speaking countries) we use this format: €1.000,00, but apparently this formatting is exclusive to Dutch, Irish and Maltese.

I feel like the most intuitive solution for this issue would be applying the same rules that we use with fallbackLocale for messages but for numberFormat and perhaps datetimeFormat as well. It would achieve the same result as your proposal in #2054 but without changing the existing API, unless we want this to be configurable in some way.

@BobbieGoede
Copy link
Member

I feel like the most intuitive solution for this issue would be applying the same rules that we use with fallbackLocale for messages but for numberFormat and perhaps datetimeFormat as well.

After looking into this, I think we already do this 🤔 (I haven't tested it though)

@babu-ch
Copy link
Contributor

babu-ch commented Feb 26, 2025

Do you envision using fallbackLocale as follows?

      const i18n = createI18n({
        fallbackLocale: {
          en: ["de"],
          default: "en"
        },
        messages: {
          'en': {
            language: 'Language',
            money: 'Money'
          },
          'ja': {
            language: '言語',
            money: 'お金'
          },
        },
        numberFormats: {
          'ja': {
            currency: {
              style: 'currency',
              currency: 'JPY',
              currencyDisplay: 'symbol'
            }
          },
          'de': {
            currency: {
              style: 'currency',
              currency: 'EUR',
              currencyDisplay: 'symbol'
            }
          }
        }
      })

@MickL
Copy link
Author

MickL commented Feb 26, 2025

In The Netherlands (and other Dutch speaking countries) we use this format: €1.000,00

I didnt know that, thats interesting! Yes I never saw this format anywhere else, only for USD or Pounds.

FallbackLocale would be an option for my specific case but the downside is that it cant be distinguished between messages an number and date. For example one would like to use 'en' fallback for messages but for currency he wants to display the european format and therefor not use 'en' but 'fr'. And still it wouldnt be possible to use 'fr' locale for currency of locale 'en' (because otherwise it is not possible to make Intl format 'en' to european currency style)

FallbackLocale does currently work but has some downsides:

  1. The dev logs are spammed with warnings. 50 products on a page result in 100 logs.
Image
  1. TypeScript complains that numberFormat's and dateFormat's are missing
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

3 participants