-2

我正在尝试使用 Nuxt/i18n 本地化 DateTime ,

但它不起作用!

这个我在 nuxt config 中配置 Nuxt/i18n

  {
        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',
            },
          
          },
        },
      },

我怎样才能解决这个问题 ?

我怎样才能解决这个问题 ?

我怎样才能解决这个问题 ?

4

1 回答 1

1

在 nuxt.config.js 的 i18n 部分使用 vueI18n 选项

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'
            }
       }
     }
   }
 }
],

另见这篇文章

于 2021-10-18T09:06:00.843 回答