适配小程序代码结构

This commit is contained in:
zhonghua1
2026-01-20 08:46:36 +08:00
parent 3b169467ac
commit 9c00db8ff5
615 changed files with 62726 additions and 8 deletions

View File

@@ -0,0 +1,78 @@
"use strict";
const common_vendor = require("../common/vendor.js");
const lang_en = require("./en.js");
const lang_zhHans = require("./zh-Hans.js");
const uniStarter_config = require("../uni-starter.config.js");
const { i18n: { enable: i18nEnable } } = uniStarter_config.config;
const messages = {
"en": lang_en.langEn,
"zh-Hans": lang_zhHans.zhHans
};
let currentLang;
if (i18nEnable) {
currentLang = common_vendor.index.getStorageSync("CURRENT_LANG");
} else {
currentLang = "zh-Hans";
}
if (!currentLang) {
if (common_vendor.index.getLocale) {
common_vendor.index.__f__("log", "at lang/i18n.js:18", "获取应用语言:", common_vendor.index.getLocale());
let language = "en";
if (common_vendor.index.getLocale() != "en") {
language = "zh-Hans";
}
common_vendor.index.setStorageSync("CURRENT_LANG", language);
currentLang = language;
} else {
common_vendor.index.getSystemInfo({
success: function(res) {
common_vendor.index.__f__("log", "at lang/i18n.js:28", "获取设备信息:", res);
let language = "zh-Hans";
if (res.language == "en") {
language = "en";
}
common_vendor.index.setStorageSync("CURRENT_LANG", language);
currentLang = language;
},
fail: (err) => {
common_vendor.index.__f__("error", "at lang/i18n.js:37", err);
}
});
}
}
let i18nConfig = {
locale: currentLang,
// set locale
messages
// set locale messages
};
const i18n = common_vendor.createI18n(i18nConfig);
if (i18nEnable) {
common_vendor.index.__f__("log", "at lang/i18n.js:65", `
你已开启多语言国际化将自动根据语言获取【lang/en.js】或【lang/zh-Hans.js】文件中配置的tabbar的值
覆盖你在pages.json中的tabbar的值
如果你不需要多语言国际化请打开配置文件uni-starter.config.js找到 -> i18n -> enable把值设置为false
`);
let initLanguageAfter = () => {
function $i18n(e) {
return i18n.global.messages[i18n.global.locale][e];
}
setTimeout(function() {
$i18n("tabbar").split(",").forEach((text, index) => {
common_vendor.index.setTabBarItem({
index,
text,
complete: () => {
}
});
});
}, 1);
};
initLanguageAfter();
common_vendor.index.$on("changeLanguage", (e) => {
common_vendor.index.__f__("log", "at lang/i18n.js:90", "changeLanguage", e);
initLanguageAfter();
});
}
exports.i18n = i18n;
//# sourceMappingURL=../../.sourcemap/mp-weixin/lang/i18n.js.map