kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js

Home Page:https://kazupon.github.io/vue-i18n/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic currency

darrachequesne opened this issue · comments

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:

  • explicit number format option (added in #305)
$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