diff --git a/package.json b/package.json index 95f6177..ddb5346 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "vue": "^2.6.11", "vue-analytics": "^5.22.1", "vue-global-events": "^1.2.1", + "vue-i18n": "^8.22.0", "vue-router": "^3.4.3", "vue-slider-component": "^3.2.5", "vuex": "^3.4.0" diff --git a/src/assets/icons/translation.svg b/src/assets/icons/translation.svg new file mode 100644 index 0000000..9cbd770 --- /dev/null +++ b/src/assets/icons/translation.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index 7c32e19..c14eb35 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -10,17 +10,17 @@
@@ -32,7 +32,7 @@
+
+ +
@@ -57,6 +61,7 @@ export default { return { inputFocus: false, keywords: "", + langs: ['zh-CN', 'en'] }; }, methods: { @@ -70,6 +75,12 @@ export default { query: { keywords: this.keywords }, }); }, + changeLang() { + if (this.$i18n.locale === "zh-CN") { + return this.$i18n.locale = "en"; + } + this.$i18n.locale = "zh-CN"; + } }, }; @@ -133,6 +144,7 @@ nav { color: #335eea; } } + .search { .svg-icon { height: 18px; @@ -193,4 +205,15 @@ nav { width: 24px; } } + +.locale-changer { + position: relative; + .translation { + margin-left: 16px; + height: 48px; + width: 48px; + } +} + + diff --git a/src/locale/index.js b/src/locale/index.js new file mode 100644 index 0000000..5005c24 --- /dev/null +++ b/src/locale/index.js @@ -0,0 +1,12 @@ +import Vue from 'vue'; +import VueI18n from 'vue-i18n' +import messages from './messages'; + +Vue.use(VueI18n) + +const i18n = new VueI18n({ + locale: 'zh-CN', + messages +}); + +export default i18n; \ No newline at end of file diff --git a/src/locale/messages.js b/src/locale/messages.js new file mode 100644 index 0000000..43fb8cb --- /dev/null +++ b/src/locale/messages.js @@ -0,0 +1,18 @@ +export default { + en: { + message: { + home: 'Home', + explore: 'Explore', + library: 'Library', + search: 'Search' + } + }, + 'zh-CN': { + message: { + home: '首页', + explore: '发现', + library: '歌单', + search: '搜索' + } + } +}; diff --git a/src/main.js b/src/main.js index 11017bf..dd8958d 100644 --- a/src/main.js +++ b/src/main.js @@ -3,6 +3,7 @@ import VueAnalytics from "vue-analytics"; import App from "./App.vue"; import router from "./router"; import store from "./store"; +import i18n from '@/locale'; import "@/assets/icons"; import "@/utils/filters"; import { initMediaSession } from "@/utils/mediaSession"; @@ -18,6 +19,7 @@ Vue.config.productionTip = false; initMediaSession(); new Vue({ + i18n, store, router, render: (h) => h(App), diff --git a/yarn.lock b/yarn.lock index 3836b5b..efd1ac5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8535,6 +8535,11 @@ vue-hot-reload-api@^2.3.0: resolved "https://registry.npm.taobao.org/vue-hot-reload-api/download/vue-hot-reload-api-2.3.4.tgz?cache=0&sync_timestamp=1589682714858&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-hot-reload-api%2Fdownload%2Fvue-hot-reload-api-2.3.4.tgz#532955cc1eb208a3d990b3a9f9a70574657e08f2" integrity sha1-UylVzB6yCKPZkLOp+acFdGV+CPI= +vue-i18n@^8.22.0: + version "8.22.0" + resolved "https://registry.npm.taobao.org/vue-i18n/download/vue-i18n-8.22.0.tgz?cache=0&sync_timestamp=1602001179053&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-i18n%2Fdownload%2Fvue-i18n-8.22.0.tgz#6403381a6eab1d229e515a62addb29b2ff3abfed" + integrity sha1-ZAM4Gm6rHSKeUVpirdspsv86v+0= + "vue-loader-v16@npm:vue-loader@^16.0.0-beta.7": version "16.0.0-beta.7" resolved "https://registry.npm.taobao.org/vue-loader/download/vue-loader-16.0.0-beta.7.tgz?cache=0&sync_timestamp=1599639283575&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-loader%2Fdownload%2Fvue-loader-16.0.0-beta.7.tgz#6f2726fa0e2b1fbae67895c47593bbf69f2b9ab8"