Skip to content

Commit 8f9d374

Browse files
fix: 支持单独翻译时间戳 close #1281
1 parent eb7e7cb commit 8f9d374

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/plugin/syringe/index.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class TagNodeRef {
140140
else value = `${this.service.tagging.ns(originalNs)}:${value}`;
141141
}
142142
this.node.innerHTML = value;
143-
this.node.setAttribute('lang', 'cmn-Hans');
143+
this.node.setAttribute('lang', 'zh-hans');
144144
return true;
145145
}
146146
}
@@ -308,7 +308,7 @@ export class Syringe {
308308
node.classList.add('ehs-translate-tag');
309309
}
310310
if (this.config.translateUi) {
311-
node.setAttribute('lang', 'cmn-Hans');
311+
node.setAttribute('lang', 'zh-hans');
312312
} else {
313313
node.setAttribute('lang', 'en');
314314
}
@@ -325,7 +325,7 @@ export class Syringe {
325325

326326
const handled = this.translateTag(node);
327327
/* tag 处理过的ui不再处理*/
328-
if (!handled && this.config.translateUi) {
328+
if (!handled && (this.config.translateUi || this.config.translateTimestamp)) {
329329
this.translateUi(node);
330330
}
331331
}
@@ -382,17 +382,20 @@ export class Syringe {
382382
}
383383

384384
private translateUiText(text: string): string | undefined {
385-
const plain = this.uiData.plainReplacements.get(text);
386-
if (plain != null) return plain;
387-
388385
let repText = text;
389-
for (const [k, v] of this.uiData.regexReplacements) {
390-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
391-
repText = repText.replace(k, v as (substring: string, ...args: any[]) => string);
386+
387+
if (this.config.translateUi) {
388+
const plain = this.uiData.plainReplacements.get(text);
389+
if (plain != null) return plain;
390+
391+
for (const [k, v] of this.uiData.regexReplacements) {
392+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
393+
repText = repText.replace(k, v as (substring: string, ...args: any[]) => string);
394+
}
392395
}
393396

394397
if (
395-
this.config.translateTimestamp !== false &&
398+
this.config.translateTimestamp &&
396399
// 快速判断是否有可能包含时间戳
397400
repText.includes(':')
398401
) {
@@ -486,7 +489,7 @@ export class Syringe {
486489
}
487490

488491
if (isElement(node, 'p') && node.classList.contains('gpc')) {
489-
/* 兼容熊猫书签,单独处理页码,保留原页码Element,防止熊猫书签取不到报错 */
492+
/* 兼容熊猫书签,单独处理页码,保留原页码 Element,防止熊猫书签取不到报错 */
490493
this.cloneAndPrependElement(node);
491494
}
492495

src/user-script/popup-host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function createPopup(): void {
119119
setBadge({ text: '' });
120120
const popupBack = document.body.appendChild(document.createElement('div'));
121121
popupBack.id = 'eh-syringe-popup-back';
122-
popupBack.lang = 'cmn-Hans';
122+
popupBack.lang = 'zh-hans';
123123
const popup = popupBack.appendChild(document.createElement('div'));
124124
popup.id = 'eh-syringe-popup';
125125

src/web-ext/popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="cmn-Hans">
2+
<html lang="zh-hans">
33
<head>
44
<meta charset="UTF-8" />
55
<title><%= htmlWebpackPlugin.options.title %></title>

0 commit comments

Comments
 (0)