diff --git a/assets/image/icon/language.png b/assets/image/icon/language.png
new file mode 100644
index 0000000..288a43b
Binary files /dev/null and b/assets/image/icon/language.png differ
diff --git a/components/header.vue b/components/header.vue
index db205f1..8ab3096 100644
--- a/components/header.vue
+++ b/components/header.vue
@@ -16,6 +16,9 @@
@keydown.enter="search"
>
+
+
+
@@ -37,6 +40,9 @@
:alt="$t('common.menu')"
@click="$refs.menuDrawerRef.drawer=true"
/>
+
+
+
diff --git a/locales/en.json b/locales/en.json
index af81e30..5d92806 100644
--- a/locales/en.json
+++ b/locales/en.json
@@ -31,7 +31,8 @@
"next": "Next",
"prev": "Prev",
"submitSuccess": "Submit success",
- "fulltextsearch": "Full text search"
+ "fulltextsearch": "Full text search",
+ "language": "Language"
},
"menu": {
"Home": "Home",
diff --git a/locales/zh.json b/locales/zh.json
index 7818660..1f3d120 100644
--- a/locales/zh.json
+++ b/locales/zh.json
@@ -31,7 +31,8 @@
"next": "下一个",
"prev": "上一个",
"submitSuccess": "提交成功",
- "fulltextsearch": "全站搜索"
+ "fulltextsearch": "全站搜索",
+ "language": "语言"
},
"menu": {
"Home": "首页",
diff --git a/middleware/i18n.js b/middleware/i18n.js
index 4a86ec3..64c0ac9 100644
--- a/middleware/i18n.js
+++ b/middleware/i18n.js
@@ -4,10 +4,11 @@ export default function ({
store,
route,
query,
+ $cookies,
error,
redirect
}) {
- const defaultLocale = app.i18n.fallbackLocale
+ const defaultLocale = $cookies.get('lang') || app.i18n.fallbackLocale
if (isHMR) {
return
}
@@ -15,6 +16,7 @@ export default function ({
if (!store.state.locales.includes(locale)) {
return error({ message: 'This page could not be found.', statusCode: 404 })
}
+
store.commit('SET_LANG', locale)
app.i18n.locale = store.state.locale
diff --git a/store/index.js b/store/index.js
index 4d6e24f..e87214d 100644
--- a/store/index.js
+++ b/store/index.js
@@ -16,6 +16,7 @@ export const mutations = {
SET_LANG (state, locale) {
if (state.locales.includes(locale)) {
state.locale = locale
+ this.$cookies.set('lang', locale)
}
},
SET_FOOTER_INFO (state, info) {