diff --git a/src/i18n/en.js b/src/i18n/en.js new file mode 100644 index 0000000..80fede6 --- /dev/null +++ b/src/i18n/en.js @@ -0,0 +1,6 @@ +const t = {} + +t.loading = 'Loading...' +t.createTime = 'Create Time' + +export default t \ No newline at end of file diff --git a/src/i18n/index.js b/src/i18n/index.js index eb668d6..050ea5c 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -2,8 +2,9 @@ import Vue from 'vue' import VueI18n from 'vue-i18n' import Cookies from 'js-cookie' import zhCNLocale from 'element-ui/lib/locale/lang/zh-CN' +import enLocale from 'element-ui/lib/locale/lang/en' import zhCN from './zh-CN' - +import en from './en' Vue.use(VueI18n) export const messages = { @@ -11,11 +12,33 @@ export const messages = { '_lang': '简体中文', ...zhCN, ...zhCNLocale + }, + 'en': { + '_lang': 'English', + ...en, + ...enLocale } } +export function getLanguage() { + const chooseLanguage = Cookies.get('language') + if (chooseLanguage) return chooseLanguage + + // if has not choose language + const language = (navigator.language || navigator.browserLanguage).toLowerCase() + const locales = Object.keys(messages) + for (const locale of locales) { + if (language.indexOf(locale) > -1) { + Cookies.set('language', locale) + return locale + } + } + Cookies.set('language', 'zh-CN') + return 'zh-CN' +} + export default new VueI18n({ // locale: Cookies.get('language') || 'zh-CN', - locale: 'zh-CN', // 先默认中文 + locale: getLanguage(), // 先默认中文 messages }) diff --git a/src/i18n/zh-CN.js b/src/i18n/zh-CN.js index 22bb0a6..7f215f7 100644 --- a/src/i18n/zh-CN.js +++ b/src/i18n/zh-CN.js @@ -1,6 +1,7 @@ const t = {} t.loading = '加载中...' +t.createTime = '添加时间' t.brand = {} t.brand.lg = '生产监控系统' diff --git a/src/views/main-navbar.vue b/src/views/main-navbar.vue index b900bb4..86161a0 100644 --- a/src/views/main-navbar.vue +++ b/src/views/main-navbar.vue @@ -1,18 +1,38 @@