多语言优化

master
gongfuxiang 2024-07-05 10:08:43 +08:00
parent b2f5ae64b9
commit 21762369f2
5 changed files with 9 additions and 18 deletions

17
App.vue
View File

@ -1,7 +1,7 @@
<script> <script>
import base64 from './common/js/lib/base64.js'; import base64 from './common/js/lib/base64.js';
// //
import i18n from './lang/index'; import i18n from './locale/index';
export default { export default {
globalData: { globalData: {
data: { data: {
@ -46,7 +46,7 @@
// //
// 1. // 1.
// 2.lang // 2.lang
default_language: 'zh-Hans', default_language: 'zh',
// tabbar // tabbar
tabbar_pages: ['/pages/index/index', '/pages/goods-category/goods-category', '/pages/cart/cart', '/pages/user/user'], tabbar_pages: ['/pages/index/index', '/pages/goods-category/goods-category', '/pages/cart/cart', '/pages/user/user'],
@ -322,17 +322,8 @@
var user_location = this.choice_user_location_init(); var user_location = this.choice_user_location_init();
var user_location_params = (user_location || null) != null && (user_location.status || 0) == 1 ? '&user_lng=' + user_location.lng + '&user_lat=' + user_location.lat : ''; var user_location_params = (user_location || null) != null && (user_location.status || 0) == 1 ? '&user_lng=' + user_location.lng + '&user_lat=' + user_location.lat : '';
// //
var lang_list = { var lang = this.get_language_value();
'zh-Hans': 'zh',
'zh-Hant': 'cht',
en: 'en',
fr: 'fra',
es: 'spa',
};
var lang = lang_list[this.get_language_value()] || null;
if (lang == null) {
lang = 'zh';
}
// //
var join = url.indexOf('?') == -1 ? '?' : '&'; var join = url.indexOf('?') == -1 ? '?' : '&';
return url + join + 'system_type=' + this.data.system_type + '&application=app&application_client_type=' + client_value + '&token=' + token + '&uuid=' + uuid + referrer_params + user_location_params + '&lang=' + lang; return url + join + 'system_type=' + this.data.system_type + '&application=app&application_client_type=' + client_value + '&token=' + token + '&uuid=' + uuid + referrer_params + user_location_params + '&lang=' + lang;

View File

@ -1,6 +1,6 @@
{ {
"language": { "language": {
"zh-Hans": "Simplified Chinese", "zh": "Simplified Chinese",
"en": "English" "en": "English"
}, },
"common": { "common": {

View File

@ -1,14 +1,14 @@
import VueI18n from 'vue-i18n'; import VueI18n from 'vue-i18n';
import Vue from 'vue'; import Vue from 'vue';
import zhHans from './zh.json'; import zh from './zh.json';
import en from './en.json'; import en from './en.json';
let i18nConfig = { let i18nConfig = {
locale: uni.getLocale(), locale: uni.getLocale(),
silentTranslationWarn: true, silentTranslationWarn: true,
messages: { messages: {
"zh-Hans": zhHans, "zh": zh,
"en": en "en": en
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"language": { "language": {
"zh-Hans": "简体中文", "zh": "简体中文",
"en": "英语" "en": "英语"
}, },
"common": { "common": {

View File

@ -6,7 +6,7 @@ import base from './common/js/common/base';
import share from './common/js/common/share'; import share from './common/js/common/share';
// 多语言引入并初始化 // 多语言引入并初始化
import i18n from './lang/index' import i18n from './locale/index'
// 全局icon组件 // 全局icon组件
import iconfont from './components/iconfont/iconfont.vue' import iconfont from './components/iconfont/iconfont.vue'