Files
smartDriveEEUniApp/unpackage/dist/dev/mp-weixin/lang/i18n.js
2026-02-01 09:49:48 +08:00

97 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"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) {
try {
if (i18n && i18n.global && i18n.global.messages && i18n.global.locale) {
return i18n.global.messages[i18n.global.locale][e];
}
if (i18n && i18n.messages && i18n.locale) {
return i18n.messages[i18n.locale][e];
}
return "";
} catch (error) {
common_vendor.index.__f__("error", "at lang/i18n.js:86", "[i18n] 获取翻译文本失败:", error);
return "";
}
}
setTimeout(function() {
try {
const tabbarText = $i18n("tabbar");
if (tabbarText) {
tabbarText.split(",").forEach((text, index) => {
common_vendor.index.setTabBarItem({
index,
text,
complete: () => {
}
});
});
}
} catch (error) {
common_vendor.index.__f__("error", "at lang/i18n.js:104", "[i18n] 更新 tabbar 失败:", error);
}
}, 1);
};
initLanguageAfter();
common_vendor.index.$on("changeLanguage", (e) => {
common_vendor.index.__f__("log", "at lang/i18n.js:110", "changeLanguage", e);
initLanguageAfter();
});
}
exports.i18n = i18n;
//# sourceMappingURL=../../.sourcemap/mp-weixin/lang/i18n.js.map