diff --git a/public/themes/dist_static/static/js/common.js b/public/themes/dist_static/static/js/common.js index 6532e25..bcd6ba0 100644 --- a/public/themes/dist_static/static/js/common.js +++ b/public/themes/dist_static/static/js/common.js @@ -30,6 +30,67 @@ })(); //#endregion //#region js/common.js +const UI_I18N = { + zh: { + "video.play": "视频播放", + "filter.by_product": "按产品筛选", + "about.expand_more": "展开更多", + "about.collapse": "收起", + "brand.short": "睿能科技", + "stock.delay_note": "截止 {time}*报价有十五分钟或以上延迟。", + "contact.name_required": "请输入姓名", + "contact.phone_required": "请输入手机号", + "contact.company_required": "请输入公司名称", + "contact.email_required": "请输入邮箱", + "contact.submitting": "提交中...", + "contact.submit": "提交", + "contact.success": "提交成功,我们会尽快与您联系!", + "contact.fail": "提交失败,请稍后重试", + "contact.network_error": "网络错误,请稍后重试", + "earth.hq_fuzhou_html": "全球总部
福州" + }, + en: { + "video.play": "Video", + "filter.by_product": "Filter by product", + "about.expand_more": "Show more", + "about.collapse": "Show less", + "brand.short": "RAYNEN", + "stock.delay_note": "As of {time}* Quotes delayed by 15 minutes or more.", + "contact.name_required": "Please enter your name", + "contact.phone_required": "Please enter your phone number", + "contact.company_required": "Please enter your company name", + "contact.email_required": "Please enter your email", + "contact.submitting": "Submitting...", + "contact.submit": "Submit", + "contact.success": "Submitted successfully. We will contact you soon.", + "contact.fail": "Submission failed. Please try again later.", + "contact.network_error": "Network error. Please try again later.", + "earth.hq_fuzhou_html": "Global HQ
Fuzhou" + } +}; + +function getUiLang() { + const fromHeader = document.querySelector(".site-header__lang")?.getAttribute("data-lang-current"); + if (fromHeader === "en" || fromHeader === "zh") return fromHeader; + const seg = location.pathname.replace(/^\//, "").split("/")[0] || ""; + return seg === "en" ? "en" : "zh"; +} + +function t(key, vars) { + const lang = getUiLang(); + const table = UI_I18N[lang] || UI_I18N.zh; + let str = table[key] ?? UI_I18N.zh[key] ?? key; + if (vars && typeof vars === "object") { + Object.keys(vars).forEach((k) => { + str = str.replace(new RegExp(`\\{${k}\\}`, "g"), String(vars[k])); + }); + } + return str; +} + +window.getUiLang = getUiLang; +window.t = t; + $(function() { AOS.init({ duration: 800 }); const lenis = new Lenis(); @@ -41,69 +102,6 @@ $(function() { }); gsap.ticker.lagSmoothing(0); - const UI_I18N = { - zh: { - "video.play": "视频播放", - "filter.by_product": "按产品筛选", - "about.expand_more": "展开更多", - "about.collapse": "收起", - "brand.short": "睿能科技", - "stock.delay_note": "截止 {time}*报价有十五分钟或以上延迟。", - "contact.name_required": "请输入姓名", - "contact.phone_required": "请输入手机号", - "contact.company_required": "请输入公司名称", - "contact.email_required": "请输入邮箱", - "contact.submitting": "提交中...", - "contact.submit": "提交", - "contact.success": "提交成功,我们会尽快与您联系!", - "contact.fail": "提交失败,请稍后重试", - "contact.network_error": "网络错误,请稍后重试", - "earth.hq_fuzhou": "全球总部福州", - "earth.hq_fuzhou_html": "全球总部
福州" - }, - en: { - "video.play": "Video", - "filter.by_product": "Filter by product", - "about.expand_more": "Show more", - "about.collapse": "Show less", - "brand.short": "RAYNEN", - "stock.delay_note": "As of {time}* Quotes delayed by 15 minutes or more.", - "contact.name_required": "Please enter your name", - "contact.phone_required": "Please enter your phone number", - "contact.company_required": "Please enter your company name", - "contact.email_required": "Please enter your email", - "contact.submitting": "Submitting...", - "contact.submit": "Submit", - "contact.success": "Submitted successfully. We will contact you soon.", - "contact.fail": "Submission failed. Please try again later.", - "contact.network_error": "Network error. Please try again later.", - "earth.hq_fuzhou": "Global HQ Fuzhou", - "earth.hq_fuzhou_html": "Global HQ
Fuzhou" - } - }; - - function getUiLang() { - const fromHeader = document.querySelector(".site-header__lang")?.getAttribute("data-lang-current"); - if (fromHeader === "en" || fromHeader === "zh") return fromHeader; - const seg = location.pathname.replace(/^\//, "").split("/")[0] || ""; - return seg === "en" ? "en" : "zh"; - } - - function t(key, vars) { - const lang = getUiLang(); - const table = UI_I18N[lang] || UI_I18N.zh; - let str = table[key] ?? UI_I18N.zh[key] ?? key; - if (vars && typeof vars === "object") { - Object.keys(vars).forEach((k) => { - str = str.replace(new RegExp(`\\{${k}\\}`, "g"), String(vars[k])); - }); - } - return str; - } - - window.getUiLang = getUiLang; - window.t = t; - const $header = $(".site-header"); const $mask = $(".mask"); const $targets = $("[data-header-dark]"); diff --git a/public/themes/dist_static/static/js/earth.js b/public/themes/dist_static/static/js/earth.js index ceb86d6..6104258 100644 --- a/public/themes/dist_static/static/js/earth.js +++ b/public/themes/dist_static/static/js/earth.js @@ -7,7 +7,6 @@ var location_default = "data:image/svg+xml,%3csvg%20viewBox='0%200%2030%2041.184 //#region js/earth.js (function() { const getUiLang = window.getUiLang || (() => (location.pathname.split("/")[1] === "en" ? "en" : "zh")); - const t = window.t || ((k) => k); function markerName(data) { return getUiLang() === "en" ? (data.nameEn || data.nameZh) : (data.nameZh || data.nameEn); } @@ -371,7 +370,7 @@ var location_default = "data:image/svg+xml,%3csvg%20viewBox='0%200%2030%2041.184 tooltip.classList.add("tooltip-arrow"); container.appendChild(tooltip); const fuzhouTooltip = tooltip.cloneNode(true); - fuzhouTooltip.innerHTML = t("earth.hq_fuzhou_html"); + fuzhouTooltip.innerHTML = (window.t || ((k) => k))("earth.hq_fuzhou_html"); container.appendChild(fuzhouTooltip); const raycaster = new THREE.Raycaster(); const mouse = new THREE.Vector2();