- popup.js 拆分为 i18n/crypto-file/strength/messaging/ui-utils 五个 ES 模块 - 所有源码迁移至 src/ 目录,tsconfig strict 模式零错误编译 - globals.d.ts 定义 EnvStore/CryptoStore 完整接口与全局类型 - manifest.json 与 popup.html 引用 dist/ 编译产物 - 删除无效的 sidePanel.setOptions panelWidth 调用
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
export function t(key, ...args) {
|
|
const msg = chrome.i18n.getMessage(key, args);
|
|
return msg || key;
|
|
}
|
|
export function applyI18n(root = document) {
|
|
root.querySelectorAll("[data-i18n]").forEach((el) => {
|
|
const key = el.dataset.i18n || "";
|
|
if (el.children.length === 0) {
|
|
const msg = chrome.i18n.getMessage(key);
|
|
if (msg)
|
|
el.textContent = msg;
|
|
}
|
|
else {
|
|
const msg = chrome.i18n.getMessage(key);
|
|
if (msg) {
|
|
const firstText = el.firstChild;
|
|
if (firstText && firstText.nodeType === Node.TEXT_NODE) {
|
|
firstText.nodeValue = msg;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
root.querySelectorAll("[data-i18n-placeholder]").forEach((el) => {
|
|
const key = el.dataset.i18nPlaceholder || "";
|
|
const msg = chrome.i18n.getMessage(key);
|
|
if (msg)
|
|
el.placeholder = msg;
|
|
});
|
|
root.querySelectorAll("[data-i18n-title]").forEach((el) => {
|
|
const key = el.dataset.i18nTitle || "";
|
|
const msg = chrome.i18n.getMessage(key);
|
|
if (msg)
|
|
el.title = msg;
|
|
});
|
|
root.querySelectorAll("[data-i18n-aria]").forEach((el) => {
|
|
const key = el.dataset.i18nAria || "";
|
|
const msg = chrome.i18n.getMessage(key);
|
|
if (msg)
|
|
el.setAttribute("aria-label", msg);
|
|
});
|
|
}
|