nathanchase/dayjs

Support default language settings?

Closed this issue · 8 comments

Support default language settings?
I set locale as follows, but it didn't work.

export default defineNuxtConfig({
 modules: [
    '@nathanchase/nuxt-dayjs-module'
  ],
  dayjs: {
    locales: [
      'ko'
    ],
    defaultLocale: 'ko',
    plugins: [
      'relativeTime',
      'isoWeek',
      'utc',
      'weekday',
      'isToday',
      'isSameOrBefore',
      'isSameOrAfter',
      'localizedFormat',
      'timezone',
      'updateLocale'
    ]
  }
})

Thank you for your open source contribution!

Yeah, currently it only supports plugins in the config. I can take a look and see if it's easy to add the locales like you have above. Thanks for the request.

The code actually looks like locales are already supported, but maybe you have to add localeData as a plugin? https://day.js.org/docs/en/plugin/locale-data

Sorry, I've not dealt with locales with dayjs before.

@nathanchase Thank you for your reply.

Were you able to get it working @initred? Did the localeData plug-in do the trick?

Hi @nathanchase. I did try adding localeData as plugin and it didn't work for me. Thank you.

@nathanchase @rafaponieman I created a new module and developed it. All types are supported and all functions are functional. However, the testing code and error handling are insufficient. If you're in a hurry, you can use it.
There was no particular error when I used it. Please refer to my repository.

Hi @nathanchase @rafaponieman @initred, i have issues with multi lang support.
My solution was change the line
${locales.map(l => import 'dayjs/locale/${l}').join('\n')}
to
${locales.map(l => import 'dayjs/esm/locale/${l}').join('\n')}
in src/gen.ts because you are loading dayjs from dayjs/esm/index.js, and now works great.
Thanks for this module @nathanchase

Hi @nathanchase @rafaponieman @initred, i have issues with multi lang support.

My solution was change the line

${locales.map(l => import 'dayjs/locale/${l}').join('\n')}

to

${locales.map(l => import 'dayjs/esm/locale/${l}').join('\n')}

in src/gen.ts because you are loading dayjs from dayjs/esm/index.js, and now works great.

Thanks for this module @nathanchase

Thanks! Submit this as a PR and I can merge in this fix.