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

Dynamic currency #1697

Open
3 tasks done
darrachequesne opened this issue Feb 9, 2024 · 0 comments
Open
3 tasks done

Dynamic currency #1697

darrachequesne opened this issue Feb 9, 2024 · 0 comments
Labels
Status: Proposal Request for comments

Comments

@darrachequesne
Copy link

darrachequesne commented Feb 9, 2024

Clear and concise description of the problem

Hi!

If I'm not mistaken, the currency is currently tied to the locale:

const i18n = new VueI18n({
  numberFormats: {
    'en-US': {
      currency: {
        style: 'currency',
        currency: 'USD'
      }
    },
    'fr-FR': {
      currency: {
        style: 'currency',
        currency: 'EUR'
      }
    }
  }
});

So $n(100, 'currency') will print 100 € if the locale is set to fr-FR and $100 if it's en-US.

Which is problematic if a American wants to do some business in euro in France.

Reference: https://kazupon.github.io/vue-i18n/guide/number.html

Suggested solution

I'd like to be able to set the current currency:

i18n.currency = "EUR";

So that $n(100, 'currency') returns the correct label.

Alternative

If I understand correctly, there are currently two alternatives:

$n(100, { style: "currency", currency: theCurrentCurrency })

But that requires including the theCurrentCurrency variable everywhere.

  • mergeNumberFormat()
i18n.mergeNumberFormat(i18n.locale, {
  currency: {
    style: 'currency',
    currency: 'EUR'
  }
});

But this requires calling mergeNumberFormat() every time the locale or the currency is updated.

Reference: https://kazupon.github.io/vue-i18n/api/#mergenumberformat-locale-format

Additional context

Possibly related:

Validations

@darrachequesne darrachequesne added the Status: Proposal Request for comments label Feb 9, 2024
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

1 participant