Search code examples
vue.jsinternationalizationnuxt.jsnuxt-i18n

How to localize currency lNuxtJS i18n


As you know currency format differs in Europe countries . in Germany 1.234.567,89 in England 1.234.567.89 how can i use nuxt/i18n localization for currency . i have this code in nuxt config

i18n: {
  locales: [
    { code: 'en', iso: 'en-US', dir: 'ltr' },
    { code: 'de', iso: 'de-GER', dir: 'ltr' },
  ],
  defaultLocale: 'de',
  vueI18n: {
    numberFormats: {
      'en-US': {
        currency: {
           style: 'currency', 
            currency: 'USD',
            currencyDisplay: 'USD'
           }
      },
      'de-GER': {
        currency: {
           style: 'currency', 
            currency: 'EUR',
            currencyDisplay: 'EUR'
           }
      }
    },
    fallbackLocale: 'de',
    messages: {
      en: en.messages,
      de: de.messages,
    },
  },
},

and when i use

<p>{{ $n(100, 'currency') }}</p>

but I do get this error

RangeError
Value EUR out of range for Intl.NumberFormat options property currencyDisplay

how can I fix this?


Solution

  • Setting 'de-GE' rather than 'de-GER' fixed the issue!