kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js

Home Page:https://kazupon.github.io/vue-i18n/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dateTimeFormat in createI18n is datetimeFormat

lupodellasleppa opened this issue · comments

According to the documentation, to define datetime formats, a key dateTimeFormats shoud be passed to i18n

const i18n = new VueI18n({
  dateTimeFormats
})

However, when using createI18n this does not work.

The signature for createI18n, described in the documentation, is:

export declare function createI18n<Schema extends object = DefaultLocaleMessageSchema, Locales extends string | object = 'en-US', Legacy extends boolean = true, Options extends I18nOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>> = I18nOptions<SchemaParams<Schema, VueMessageType>, LocaleParams<Locales>>, Messages = Options['messages'] extends object ? Options['messages'] : {}, DateTimeFormats = Options['datetimeFormats'] extends object ? Options['datetimeFormats'] : {}, NumberFormats = Options['numberFormats'] extends object ? Options['numberFormats'] : {}, OptionLocale = Options['locale'] extends string ? Options['locale'] : Locale>(options: Options, LegacyVueI18n?: any): typeof options['legacy'] extends true ? I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, true> : typeof options['legacy'] extends false ? I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, false> : I18n<Messages, DateTimeFormats, NumberFormats, OptionLocale, Legacy>;

Notice the lowercase t in datetimeFormats instead of the capital T.

Expected behavior

createI18n({
    dateTimeFormats
)}

should return a new i18n object with datetime formats, instead it returns a default i18n.global.dateTimeFormats = { 'en-US': {}}

Reproduction

create a new i18n object with

createI18n({
    dateTimeFormats
)}

System Info

System:
    OS: Linux 4.15 Ubuntu 18.04.6 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 725.02 MB / 15.55 GB
    Container: Yes
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v14.17.6/bin/yarn
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Firefox: 97.0
  npmPackages:
    vue-i18n: ^9.0.0 => 9.1.9 
    vuex: ^4.0.1 => 4.0.2```

Screenshot

No response

Additional context

No response

Validations

Thank you for your feedback!
I've updated vue-i18n v9 docs, and added notice tip for datetime feature
https://vue-i18n.intlify.dev/guide/essentials/datetime.html#basic-usage

Thank you!

There is still something wrong with the typings, so this hasn't been completely resolved as far as I can tell. @kazupon

image

(renaming to dateTimeFormats removes this type error, but then it won't work, as @lupodellasleppa pointed out in OP)