nuxt with vue i18n dateTimeFormats "Incorrect locale information provided" error

Viewed 24

I am using nuxtjs with i18n, now I want to format dates based on the set locale however I can't seem to find a lot of info on how to properly set the dateTimeFormats for vueI18n in combination with Nuxt. I feel like I am close but am running into a strange error.

When I set the dateTimeformats like so in my nuxt.config file:

i18n: {
    locales: [
      'en-int',
      'en-us'],
    strategy: 'prefix',
    defaultLocale: 'en-int',
    vueI18n: {
      fallbackLocale: 'en-int',
      dateTimeFormats: {
        'en-int': {
          short: {
            day: '2-digit', month: '2-digit', year: '2-digit'
          }
        },
        'en-us': {
          short: {
            month: '2-digit', day: '2-digit', year: 'numeric'
          }
        }
      }
    }
  }

And then use the dateformatter in my component like so:

{{ $d(new Date(some-iso-date) , 'short') }}

I get a Incorrect locale information provided error.

It seems like it only accetps the en locale inside the vueI18n format, because when I try this.

i18n: {
    locales: [
      'en-int',
      'en-us'],
    strategy: 'prefix',
    defaultLocale: 'en-int',
    vueI18n: {
      fallbackLocale: 'en',
      dateTimeFormats: {
        en: {
          short: {
            day: '2-digit', month: '2-digit', year: '2-digit'
          }
        },
        'en-int': {
          short: {
            day: '2-digit', month: '2-digit', year: '2-digit'
          }
        },
        'en-us': {
          short: {
            month: '2-digit', day: '2-digit', year: 'numeric'
          }
        }
      }
    }
  }

And then force the en like so:

{{ $d(new Date(some-iso-date) , 'short', 'en') }}

it does work. It seems as if the vueI18n is not picking up on the existing i18n locales or maybe is checking them before they are set. I have tried adding locales to vueI18n options as well but that didn't work either.

Does anyone know what I am doing wrong? or is this a bug?

0 Answers
Related