Browse Source

添加国际化功能

吴洪双 5 years ago
parent
commit
00aedfe132
9 changed files with 96 additions and 10 deletions
  1. 1 0
      .gitignore
  2. 22 4
      App.vue
  3. 13 0
      common/lang/en.js
  4. 13 0
      common/lang/zh.js
  5. 2 2
      configs/env.js
  6. 13 3
      main.js
  7. 13 0
      package-lock.json
  8. 18 0
      package.json
  9. 1 1
      pages/Login/Login.vue

+ 1 - 0
.gitignore

@@ -33,3 +33,4 @@ testem.log
 Thumbs.db
 
 /unpackage/
+/node_modules/

+ 22 - 4
App.vue

@@ -1,8 +1,27 @@
 <script>
 	export default {
-		// onLaunch: function() {
-		// 	console.log('App Launch');
-		// },
+		onLaunch: function() {
+			console.log('App Launch');
+			var lan = 'zh'
+			 try {
+				const res = uni.getSystemInfoSync();
+				lan = res.language
+			} catch (e) {
+				console.log('error='+e)
+			}
+			console.log('lan='+lan); 
+			 if(lan == 'en') {
+				 this._i18n.locale = 'en-US'
+			 }
+			 if(lan == 'zh-Hans-CN' || lan=='zh') {
+				 this._i18n.locale = 'zh-CN'
+			 }
+			 uni.setTabBarItem({ index: 0,text: this.$t('tabs.tab1')});
+			 uni.setTabBarItem({ index: 1,text: this.$t('tabs.tab2')});
+			 uni.setTabBarItem({ index: 2,text: this.$t('tabs.tab3')});
+			 uni.setTabBarItem({ index: 3,text: this.$t('tabs.tab4')});
+			 uni.setTabBarItem({ index: 4,text: this.$t('tabs.tab5')});
+		},
 		// onShow: function() {
 		// 	console.log('App Show');
 		// },
@@ -11,7 +30,6 @@
 		// }
 	}
 </script>
-
 <style>
 	/*每个页面公共css */
 	/* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */

+ 13 - 0
common/lang/en.js

@@ -0,0 +1,13 @@
+export default {
+	lang: 'en',
+	login: {
+		title: 'backstage management',
+	},
+	tabs:{
+		tab1:"home",
+		tab2:"机器销售",
+		tab3:"机器排行",
+		tab4:"机器状态",
+		tab5:"我的"
+	}
+}

+ 13 - 0
common/lang/zh.js

@@ -0,0 +1,13 @@
+export default {
+	lang: 'zh',
+	login: {
+		title: '管理后台',
+	},
+	tabs:{
+		tab1:"首页",
+		tab2:"机器销售",
+		tab3:"机器排行",
+		tab4:"机器状态",
+		tab5:"我的"
+	}
+}

+ 2 - 2
configs/env.js

@@ -9,8 +9,8 @@ let configs = {
 if (process.env.NODE_ENV === 'development') {
 	// 测试环境
 	configs = Object.assign(configs, {
-		baseUrl: 'https://app.sunzee.com.cn/ShenzeeServer',
-		// baseUrl: 'http://127.0.0.1:8090',
+		// baseUrl: 'https://app.sunzee.com.cn/ShenzeeServer',
+		baseUrl: 'http://127.0.0.1:8090',
 	});
 }
 

+ 13 - 3
main.js

@@ -1,22 +1,32 @@
 import Vue from 'vue'
+import VueI18n from 'vue-i18n'
 import App from './App'
 import apis from './configs/http';
 import store from './store';
 import env from '@/configs/env';
+import zh from '@/common/lang/zh';
+import en from '@/common/lang/en';
 import mainStatistics from '@/pages/Charts/mainStatistics';
 
 
-
+Vue.use(VueI18n)
 Vue.config.productionTip = !!env.isProduction;
+const i18n = new VueI18n({  
+  locale: 'zh-CN',  // 默认选择的语言
+   messages: {
+         'zh-CN': zh,   // 中文语言包
+         'en-US': en    // 英文语言包
+       }
+});
 
 App.mpType = 'app'
 
 // Vue.prototype.serverurl="http://127.0.0.1:8090";
 Vue.prototype.serverurl="https://app.sunzee.com.cn/ShenzeeServer";
-
 Vue.prototype.$store = store;
-
+Vue.prototype._i18n = i18n;
 const app = new Vue({
+	i18n,
 	store,
 	...App,
 });

+ 13 - 0
package-lock.json

@@ -0,0 +1,13 @@
+{
+  "name": "shenzeeuniapp",
+  "version": "1.0.0",
+  "lockfileVersion": 1,
+  "requires": true,
+  "dependencies": {
+    "vue-i18n": {
+      "version": "8.15.1",
+      "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-8.15.1.tgz",
+      "integrity": "sha512-GBbz8qYCu0U2LNu4IcuFLZiuyninG4k26knvhL7GZG5Ncp4RR2VKDEH6g8gQ6I+UUBCvH2MBQVPSdxWe4DBkPw=="
+    }
+  }
+}

+ 18 - 0
package.json

@@ -0,0 +1,18 @@
+{
+  "name": "shenzeeuniapp",
+  "version": "1.0.0",
+  "description": "",
+  "main": "main.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://e.coding.net/sunzee/shenzeeUniApp.git"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "vue-i18n": "^8.15.1"
+  }
+}

+ 1 - 1
pages/Login/Login.vue

@@ -2,7 +2,7 @@
 	<view class="content">
 		<image class="logo" src="/static/icons/logo.png"></image>
 		<view class="title">
-			管理后台
+			{{$t('login.title')}}
 		</view>
 		<form @submit="loginSubmit">
 			<view class="section">