antdesignvuepro设置默认语⾔为中⽂ant design vue pro设置默认语⾔为中⽂
1. 修改src/core/bootstrap.js第29⾏改成30⾏
1 import store from '@/store'
2 import storage from 'store'
3 import {
4 ACCESS_TOKEN,
5 APP_LANGUAGE,
6 TOGGLE_CONTENT_WIDTH,
7 TOGGLE_FIXED_HEADER,
8 TOGGLE_FIXED_SIDEBAR, TOGGLE_HIDE_HEADER,
9 TOGGLE_LAYOUT, TOGGLE_NAV_THEME, TOGGLE_WEAK,
10 TOGGLE_COLOR, TOGGLE_MULTI_TAB
11 } from '@/store/mutation-types'
12 import { printANSI } from '@/utils/screenLog'
13 import defaultSettings from '@/config/defaultSettings'
14
15 export default function Initializer () {
16 printANSI() // 请⾃⾏移除该⾏. please remove this line
17
18 storemit(TOGGLE_LAYOUT, (TOGGLE_LAYOUT, defaultSettings.layout))
19 storemit(TOGGLE_FIXED_HEADER, (TOGGLE_FIXED_HEADER, defaultSettings.fixedHeader))
20 storemit(TOGGLE_FIXED_SIDEBAR, (TOGGLE_FIXED_SIDEBAR, defaultSettings.fixSiderbar))
21 storemit(TOGGLE_CONTENT_WIDTH, (TOGGLE_CONTENT_WIDTH, tWidth))
22 storemit(TOGGLE_HIDE_HEADER, (TOGGLE_HIDE_HEADER, defaultSettings.autoHideHeader))
23 storemit(TOGGLE_NAV_THEME, (TOGGLE_NAV_THEME, defaultSettings.navTheme))
24 storemit(TOGGLE_WEAK, (TOGGLE_WEAK, lorWeak))
25 storemit(TOGGLE_COLOR, (TOGGLE_COLOR, defaultSettings.primaryColor))
26 storemit(TOGGLE_MULTI_TAB, (TOGGLE_MULTI_TAB, defaultSettings.multiTab))
27 storemit('SET_TOKEN', (ACCESS_TOKEN))
28
29// store.dispatch('setLang', (APP_LANGUAGE, 'en-US'))
30 store.dispatch('setLang', (APP_LANGUAGE, 'zh-CN'))
31// last step
32 }
2.修改src/locales/index.js第7⾏改成8、12⾏改成13、16⾏改成23
1 import Vue from 'vue'
2 import VueI18n from 'vue-i18n'
3 import storage from 'store'
4 import moment from 'moment'
5
6// default lang
7// import enUS from './lang/en-US'
8 import enUS from './lang/zh-CN'
9
10 Vue.use(VueI18n)
11
12// export const defaultLang = 'en-US'
13 export const defaultLang = 'zh-CN'
14
15// const messages = {
16// 'en-US': {
17// ...enUS
18// }
19// }
20
21
22 const messages = {
23 'zh-CN': {
24 ...enUS
25 }
26 }
27
28 const i18n = new VueI18n({
29 silentTranslationWarn: true,
30 locale: defaultLang,
31 fallbackLocale: defaultLang,
32 messages
33 })
34
35 const loadedLanguages = [defaultLang]
36
37function setI18nLanguage (lang) {
38 i18n.locale = lang
39// request.headers['Accept-Language'] = lang
40 document.querySelector('html').setAttribute('lang', lang)
41return lang
42 }
43
44 export function loadLanguageAsync (lang = defaultLang) {
45return new Promise(resolve => {
46// 缓存语⾔设置
47 storage.set('lang', lang)
48if (i18n.locale !== lang) {
49if (!loadedLanguages.includes(lang)) {
50return import(/* webpackChunkName: "lang-[request]" */ `./lang/${lang}`).then(msg => {
51 const locale = msg.default
52 i18n.setLocaleMessage(lang, locale)
53 loadedLanguages.push(lang)
54 moment.Name, Locale)
55return setI18nLanguage(lang)
56 })
57 }
58return resolve(setI18nLanguage(lang))
59 }
60return resolve(lang)
61 })
62 }
63
64 export function i18nRender (key) {
65return i18n.t(`${key}`)
66 }
67
68 export default i18n
3.修改src/store/modules/app.js第32⾏改成33⾏
1 import storage from 'store'
2 import {
3 SIDEBAR_TYPE,
4 TOGGLE_MOBILE_TYPE,
5 TOGGLE_NAV_THEME,
6 TOGGLE_LAYOUT,
7 TOGGLE_FIXED_HEADER,
8 TOGGLE_FIXED_SIDEBAR,
9 TOGGLE_CONTENT_WIDTH,
10 TOGGLE_HIDE_HEADER,
11 TOGGLE_COLOR,
12 TOGGLE_WEAK,
13 TOGGLE_MULTI_TAB,
14// i18n
15 APP_LANGUAGE
16 } from '@/store/mutation-types'
17 import { loadLanguageAsync } from '@/locales'
18
19 const app = {
20 state: {
21 sideCollapsed: false,
22 isMobile: false,
23 theme: 'dark',
24 layout: '',
25 contentWidth: '',
26 fixedHeader: false,
27 fixedSidebar: false,
28 autoHideHeader: false,
29 color: '',
30 weak: false,
31 multiTab: true,
32// lang: 'en-US',
33 lang: 'zh-CN',
34 _antLocale: {}
35 },
36 mutations: {
37 [SIDEBAR_TYPE]: (state, type) => {
38 state.sideCollapsed = type
39 storage.set(SIDEBAR_TYPE, type)
40 },
41 [TOGGLE_MOBILE_TYPE]: (state, isMobile) => {
42 state.isMobile = isMobile
43 },
44 [TOGGLE_NAV_THEME]: (state, theme) => {
45 state.theme = theme
46 storage.set(TOGGLE_NAV_THEME, theme)
47 },
48 [TOGGLE_LAYOUT]: (state, mode) => {
49 state.layout = mode
50 storage.set(TOGGLE_LAYOUT, mode)
51 },
52 [TOGGLE_FIXED_HEADER]: (state, mode) => {
53 state.fixedHeader = mode
54 storage.set(TOGGLE_FIXED_HEADER, mode)
55 },
56 [TOGGLE_FIXED_SIDEBAR]: (state, mode) => {
57 state.fixedSidebar = mode
58 storage.set(TOGGLE_FIXED_SIDEBAR, mode)
59 },
60 [TOGGLE_CONTENT_WIDTH]: (state, type) => {
61 tWidth = type
62 storage.set(TOGGLE_CONTENT_WIDTH, type)
settings设置中文在哪里63 },
64 [TOGGLE_HIDE_HEADER]: (state, type) => {
65 state.autoHideHeader = type
66 storage.set(TOGGLE_HIDE_HEADER, type)
67 },
68 [TOGGLE_COLOR]: (state, color) => {
69 lor = color
70 storage.set(TOGGLE_COLOR, color)
71 },
72 [TOGGLE_WEAK]: (state, mode) => {
73 state.weak = mode
74 storage.set(TOGGLE_WEAK, mode)
75 },
76 [APP_LANGUAGE]: (state, lang, antd = {}) => {
77 state.lang = lang
78 state._antLocale = antd
79 storage.set(APP_LANGUAGE, lang)
80 },
81 [TOGGLE_MULTI_TAB]: (state, bool) => {
82 storage.set(TOGGLE_MULTI_TAB, bool)
83 state.multiTab = bool
84 }
85 },
86 actions: {
87 setLang ({ commit }, lang) {
88return new Promise((resolve, reject) => {
89 commit(APP_LANGUAGE, lang)
90 loadLanguageAsync(lang).then(() => {
91 resolve()
92 }).catch((e) => {
93 reject(e)
94 })
95 })
96 }
97 }
98 }
99
100 export default app
4.因为该框架语⾔存在了本地,所以只要清楚本地即可清除本地:
重新登录即可。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论