diff --git a/src/i18n/date.js b/src/i18n/date.js index f88891951..6d25522fc 100644 --- a/src/i18n/date.js +++ b/src/i18n/date.js @@ -27,6 +27,20 @@ export default { hour: 'numeric', minute: 'numeric', hour12: true } }, + 'zh_hant': { + short: { + year: 'numeric', month: 'short', day: 'numeric' + }, + medium: { + year: 'numeric', month: '2-digit', day: '2-digit', + hour: '2-digit', minute: '2-digit', second: '2-digit', + hourCycle: 'h23', hour12: false + }, + long: { + year: 'numeric', month: 'short', day: 'numeric', + hour: 'numeric', minute: 'numeric', hour12: true + } + }, 'ja': { short: { year: 'numeric', month: 'short', day: 'numeric' diff --git a/src/i18n/i18n.js b/src/i18n/i18n.js index 05612ad34..57dd44b21 100644 --- a/src/i18n/i18n.js +++ b/src/i18n/i18n.js @@ -10,7 +10,12 @@ Vue.use(VueI18n) const cookieLang = VueCookie.get('django_language') const browserLang = navigator.systemLanguage || navigator.language let lang = cookieLang || browserLang || 'zh' -lang = lang.slice(0, 2) +if (lang === 'zh-hant') { + lang = 'zh_hant' +} else { + lang = lang.slice(0, 2) +} + const i18n = new VueI18n({ locale: lang, fallbackLocale: 'en', diff --git a/src/i18n/langs/index.js b/src/i18n/langs/index.js index e077a59d4..edab7e469 100644 --- a/src/i18n/langs/index.js +++ b/src/i18n/langs/index.js @@ -1,7 +1,9 @@ import zhLocale from 'element-ui/lib/locale/lang/zh-CN' +import zhTWLocale from 'element-ui/lib/locale/lang/zh-TW' import enLocale from 'element-ui/lib/locale/lang/en' import jaLocale from 'element-ui/lib/locale/lang/ja' import zh from './zh.json' +import zhHant from './zh_Hant.json' import en from './en.json' import ja from './ja.json' @@ -10,6 +12,10 @@ export default { ...zhLocale, ...zh }, + zh_hant: { + ...zhTWLocale, + ...zhHant + }, en: { ...enLocale, ...en diff --git a/src/i18n/langs/removeUnusedKeys.py b/src/i18n/langs/removeUnusedKeys.py index 336f86abc..cea305a01 100644 --- a/src/i18n/langs/removeUnusedKeys.py +++ b/src/i18n/langs/removeUnusedKeys.py @@ -5,7 +5,8 @@ i18n_report_path = '/tmp/abc.json' lang_paths = { 'cn': 'cn.json', 'en': 'en.json', - 'ja': 'ja.json' + 'ja': 'ja.json', + 'zh_hant': 'zh_Hant.json' } diff --git a/src/layout/components/NavHeader/Language.vue b/src/layout/components/NavHeader/Language.vue index 8daa69a54..1a0babe26 100644 --- a/src/layout/components/NavHeader/Language.vue +++ b/src/layout/components/NavHeader/Language.vue @@ -21,6 +21,11 @@ export default { code: 'cn', cookieCode: 'zh-hans' // cookie code是为了让后端知道当前语言 }, + { + title: '中文(繁體)', + code: 'zh_hant', + cookieCode: 'zh-hant' // cookie code是为了让后端知道当前语言 + }, { title: 'English', code: 'en', @@ -64,6 +69,8 @@ export default { this.$moment.locale('en') } else if (this.currentLang.code.indexOf('ja') > -1) { this.$moment.locale('ja') + } else if (this.currentLang.code.indexOf('zh_hant') > -1) { + this.$moment.locale('zh-tw') } else { this.$moment.locale('zh-cn') } @@ -75,15 +82,19 @@ export default { window.location.reload() }, getLangCode() { - let langCode = localStorage.lang + let langCode = this.$cookie.get(this.LANG_COOKIE_NAME) if (!langCode) { - langCode = this.$cookie.get(this.LANG_COOKIE_NAME) + langCode = localStorage.lang } if (!langCode) { langCode = navigator.language || navigator.userLanguage } - langCode = langCode.substr(0, 2) - langCode = langCode.replace('zh', 'cn') + if (langCode === 'zh-hant') { + langCode = 'zh_hant' + } else { + langCode = langCode.slice(0, 2) + langCode = langCode.replace('zh', 'cn') + } return langCode } }