diff --git a/src/Time/src/main.js b/src/Time/src/main.js index d885020a3..9f3ed2485 100644 --- a/src/Time/src/main.js +++ b/src/Time/src/main.js @@ -1,8 +1,6 @@ import format from 'date-fns/format' import formatDistance from 'date-fns/formatDistance' import fromUnixTime from 'date-fns/fromUnixTime' -import zhCN from 'date-fns/locale/zh-CN' -import enUS from 'date-fns/locale/en-US' import render from '../../_utils/vue/render' import locale from '../../_mixins/locale' @@ -41,12 +39,6 @@ export default { } }, computed: { - dateFnsLocale () { - return ({ - 'zh-CN': zhCN, - 'en-US': enUS - })[this.locale] - }, dateFnsOptions () { return { locale: this.dateFnsLocale diff --git a/src/_mixins/locale.js b/src/_mixins/locale.js index cc570243c..d59a5c3fb 100644 --- a/src/_mixins/locale.js +++ b/src/_mixins/locale.js @@ -16,6 +16,15 @@ function getTranslationNamespace (locales, fallbackLocale, language, namespace) } } +function getDateFns (locales, fallbackLocale, language) { + const locale = locales[language] + if (locale) { + return locale._dateFns + } else { + return fallbackLocale._dateFns + } +} + export default function createLocaleMixin (componentLocaleNamespace) { return { inject: { @@ -31,6 +40,17 @@ export default function createLocaleMixin (componentLocaleNamespace) { return this.$naive.fallbackLocale } }, + dateFnsLocale () { + let language = null + if (this.NConfigProvider) { + language = this.NConfigProvider.inheritedLanguage + } + return getDateFns( + this.$naive.locales, + this.$naive.fallbackLocale, + language + ) + }, localeNamespace () { return this.tns(componentLocaleNamespace) } diff --git a/src/locale/enUS.js b/src/locale/enUS.js index a5e19875a..4b0380887 100644 --- a/src/locale/enUS.js +++ b/src/locale/enUS.js @@ -1,5 +1,8 @@ +import enUS from 'date-fns/locale/en-US' + export default { _name: 'en-US', + _dateFns: enUS, Popconfirm: { positiveText: 'Confirm', negativeText: 'Cancel' @@ -28,6 +31,7 @@ export default { Thu: 'Thu', Fri: 'Fri', Sat: 'Sat', + seperator: 'to', clear: 'Clear', now: 'Now', confirm: 'Confirm', diff --git a/src/locale/zhCN.js b/src/locale/zhCN.js index a3c8d9390..04e4ba331 100644 --- a/src/locale/zhCN.js +++ b/src/locale/zhCN.js @@ -1,5 +1,8 @@ +import zhCN from 'date-fns/locale/zh-CN' + export default { _name: 'zh-CN', + _dateFns: zhCN, Popconfirm: { positiveText: '确认', negativeText: '取消' @@ -28,6 +31,7 @@ export default { Thu: '四', Fri: '五', Sat: '六', + seperator: '至', clear: '清除', now: '此刻', confirm: '确认',