From 419988f3247f21e8fcc52f0f6750be1c56bec2ce Mon Sep 17 00:00:00 2001 From: Jks Liu Date: Sun, 25 Jul 2021 17:34:04 +0800 Subject: [PATCH] Quiz app zh-cn: Add zh-cn language to quiz app --- quiz-app/src/App.vue | 28 +++++++++++++++++------ quiz-app/src/assets/translations/index.js | 2 ++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/quiz-app/src/App.vue b/quiz-app/src/App.vue index a6a92613..ca812e48 100644 --- a/quiz-app/src/App.vue +++ b/quiz-app/src/App.vue @@ -3,10 +3,10 @@
@@ -30,12 +30,26 @@ export default { }, data() { return { - locale: "en", + native_name: "English", + + // Native names are from + // https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes + iso_639_1_map: { + "العربية": "ar", + "বাংলা": "bn", + "English": "en", + "中文 - 大陆简体": "zh-cn", + }, }; }, + computed: { + iso_639_1_map_keys() { + return Object.keys(this.iso_639_1_map); + } + }, watch: { - locale(val) { - this.$root.$i18n.locale = val; + native_name(val) { + this.$root.$i18n.locale = this.iso_639_1_map[val]; }, }, created() { diff --git a/quiz-app/src/assets/translations/index.js b/quiz-app/src/assets/translations/index.js index 1f118787..08cd4e01 100644 --- a/quiz-app/src/assets/translations/index.js +++ b/quiz-app/src/assets/translations/index.js @@ -2,6 +2,7 @@ import ar from './ar.json'; import bn from './bn.json'; import en from './en.json'; +import zh_cn from './zh-cn.json'; //export const defaultLocale = 'en'; @@ -9,6 +10,7 @@ const messages = { ar: ar[0], bn: bn[0], en: en[0], + "zh-cn": zh_cn[0], }; export default messages;