-2

I am trying to localize DateTime with Nuxt/i18n,
but it doesn't work!

This is what I have in the config of Nuxt/i18n in nuxt config:

  {
        seo: true,
        locales: [
          {
            code: 'en',
            iso: 'en-US',
            file: 'en.js',
            dir: 'ltr',
            name: 'English',
            id: 2,
          }
       
        ],

        lazy: true,
        langDir: 'locales/',
       
        defaultLocale: 'en',
        strategy: 'prefix_except_default',
        dateTimeFormats: {
          'en-US': {
            short: {
              year: 'numeric',
              month: 'long',
              day: 'numeric',
              weekday: 'short',
            },
            long: {
              year: 'numeric',
              month: 'short',
              day: 'numeric',
              weekday: 'short',
              hour: 'numeric',
              minute: 'numeric',
            },
          
          },
        },
      },

How can I fix this?

7ochem
  • 2,183
  • 1
  • 34
  • 42
morteza mortezaie
  • 1,002
  • 14
  • 37

1 Answers1

0

Use the vueI18n option in the i18n part of your nuxt.config.js

modules: [
['nuxt-i18n', {
   locales: [
     {
       code: 'en',
       iso: 'en-US',
       file: 'en-US.js'
     }
   ],
   lazy: true,
   langDir: 'lang/',
   defaultLocale: 'en',
   vueI18n: {
     dateTimeFormats: {
       en: {
         short: {
           year: 'numeric',
           month: 'short',
           day: 'numeric',
         },
       }
     },
     numberFormats: {
       en: {
         currency: {
            style: 'currency', 
             currency: 'USD'
            }
       }
     }
   }
 }
],

See also this post

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40