【问题标题】:nuxt-i18n : date localization doesn't work for menuxt-i18n:日期本地化对我不起作用
【发布时间】:2021-12-03 23:24:57
【问题描述】:

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

但它不起作用!

nuxt config 中 Nuxt/i18n 的这个 i 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',
            },
          
          },
        },
      },

我该如何解决这个问题?

我该如何解决这个问题?

我该如何解决这个问题?

【问题讨论】:

  • @JasonLandbridge ,因为我的代码很长而且 Stack 不允许我发帖,我不得不在更长的文本内容中添加“我该如何解决这个问题”
  • @JasonLandbridge ,我使用 ```

    {{ $d(new Date(), 'short') }}

    ``` 进行本地化,但它不起作用

标签: vue.js internationalization nuxt-i18n


【解决方案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'
            }
       }
     }
   }
 }
],

另请参阅this 帖子

【讨论】:

    猜你喜欢
    • 2019-08-21
    • 1970-01-01
    • 2021-08-03
    • 2016-05-17
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多