Home > Enterprise >  How to localize currency lNuxtJS i18n
How to localize currency lNuxtJS i18n

Time:09-29

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 get this error

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

how can I fix this?

CodePudding user response:

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

  • Related