nuxt-i18n:日期本地化对我不起作用

问题描述 投票:0回答:1

我正在尝试使用 Nuxt/i18n 本地化 DateTime,
但它不起作用!

这是我在 nuxt 配置中的 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',
            },
          
          },
        },
      },

我该如何解决这个问题?

vue.js internationalization nuxt-i18n
1个回答
0
投票

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

另见this post

© www.soinside.com 2019 - 2024. All rights reserved.