perf: 切换zh hant

This commit is contained in:
feng
2024-04-10 11:33:49 +08:00
committed by Bryan
parent 99200d58bb
commit e355abc1af
5 changed files with 43 additions and 6 deletions

View File

@@ -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'

View File

@@ -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',

View File

@@ -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

View File

@@ -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'
}

View File

@@ -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
}
}