Pārlūkot izejas kodu

完善多语言切换

mabaoyi 10 mēneši atpakaļ
vecāks
revīzija
4d9375f973

+ 4 - 2
commont/messages.js

@@ -2,13 +2,15 @@ export default {
 	"zh-CN":{
 		index:{
 			more:"更多",
-			homepage:'主页'
+			homepage:'主页',
+			switchLanguage:'切换语言'
 		}
 	},
 	"en-US":{
 		index:{
 			more:'more',
-			homepage:'homepage'
+			homepage:'homepage',
+			switchLanguage:"Switch Language"
 		}
 	}
 }

+ 1 - 1
main.js

@@ -10,7 +10,7 @@ Vue.use(VueI18n)
 Vue.config.productionTip = false
 // 多国语言包配置
 const i18n = new VueI18n ({
-	locale:"en-US",
+	locale:"zh-CN",
 	messages
 })
 

+ 3 - 0
pageC/accountSetup/accountSetup.vue

@@ -34,6 +34,9 @@
 		},
 		methods: {
 
+		},
+		created(){
+			
 		}
 	}
 </script>

+ 78 - 0
pageC/switchLanguage/switchLanguage.vue

@@ -0,0 +1,78 @@
+<template>
+	<view class="page">
+		<view class="btn-list">
+			<view class="language" data-lang="zh-CN" @tap="langChange"> <text>简体中文</text>
+				<image v-if="languageSelect=='zh-CN'" class="selected" src="../../static/mine/326.png" mode=""></image>
+			</view>
+			<view class="language" data-lang="en-US" @tap="langChange"> <text>English</text>
+				<image v-if="languageSelect=='en-US'" class="selected" src="../../static/mine/326.png" mode=""></image>
+			</view>
+			<view class="language" data-lang="es-ES" @tap="langChange"> <text>Español</text>
+				<image v-if="languageSelect=='es-ES'" class="selected" src="../../static/mine/326.png" mode=""></image>
+			</view>
+			<view class="language" data-lang="it-IT" @tap="langChange"> <text>Italiano</text>
+				<image v-if="languageSelect=='it-IT'" class="selected" src="../../static/mine/326.png" mode=""></image>
+			</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				languageSelect: ''
+			}
+		},
+
+		computed: {
+			i18n() {
+				return this.$t('index')
+			}
+		},
+		methods: {
+			langChange(e) {
+				const {
+					lang
+				} = e.currentTarget.dataset
+				uni.setStorageSync("language", lang)
+				this._i18n.locale = lang
+				this.languageSelect = lang
+				uni.setNavigationBarTitle({
+					title: this.i18n.switchLanguage
+				})
+			}
+		},
+		created() {
+			this.languageSelect = this._i18n.locale
+			uni.setNavigationBarTitle({
+				title: this.i18n.switchLanguage
+			})
+		}
+	}
+</script>
+
+<style scoped lang="scss">
+	.page {
+		padding: 20rpx 24rpx;
+
+		.btn-list {
+			background-color: #fff;
+			border-radius: 16rpx;
+			padding: 0 20rpx;
+
+			.language {
+				display: flex;
+				align-items: center;
+				justify-content: space-between;
+				height: 110rpx;
+				border-bottom: 2rpx solid rgba(151, 151, 151, 0.2);
+
+				.selected {
+					width: 36rpx;
+					height: 36rpx;
+				}
+			}
+		}
+	}
+</style>

+ 7 - 0
pages.json

@@ -150,6 +150,13 @@
 					{
 						"navigationBarTitleText" : "账号设置"
 					}
+				},
+				{
+					"path" : "switchLanguage/switchLanguage",
+					"style" : 
+					{
+						"navigationBarTitleText" : "切换语言"
+					}
 				}
 			]
 		}, {

BIN
static/mine/326.png


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/common/main.js.map


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map


+ 2 - 1
unpackage/dist/dev/mp-weixin/app.json

@@ -32,7 +32,8 @@
         "ensureMoney/ensureMoney",
         "ensureExplain/ensureExplain",
         "mineFollow/mineFollow",
-        "accountSetup/accountSetup"
+        "accountSetup/accountSetup",
+        "switchLanguage/switchLanguage"
       ]
     },
     {

+ 1 - 1
unpackage/dist/dev/mp-weixin/common/main.js

@@ -27,7 +27,7 @@ _vue.default.use(_vueI18n.default);
 _vue.default.config.productionTip = false;
 // 多国语言包配置
 var i18n = new _vueI18n.default({
-  locale: "en-US",
+  locale: "zh-CN",
   messages: _messages.default
 });
 _vue.default.prototype._i18n = i18n;

+ 4 - 2
unpackage/dist/dev/mp-weixin/common/vendor.js

@@ -21560,13 +21560,15 @@ var _default = {
   "zh-CN": {
     index: {
       more: "更多",
-      homepage: '主页'
+      homepage: '主页',
+      switchLanguage: '切换语言'
     }
   },
   "en-US": {
     index: {
       more: 'more',
-      homepage: 'homepage'
+      homepage: 'homepage',
+      switchLanguage: "Switch Language"
     }
   }
 };

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels