Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions addon/chrome/content/preferences.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@
preference="__prefsPrefix__.enableAnnotationFromSyncTranslation"
/>
</vbox>
<vbox>
<checkbox
id="__addonRef__-enableAutoTagAnnotation"
data-l10n-id="pref-basic-enableAutoTagAnnotation"
style="padding-left: 18px"
native="true"
preference="__prefsPrefix__.enableAutoTagAnnotation"
/>
<hbox align="center" style="padding-left: 36px">
<label data-l10n-id="pref-basic-annotationTagContent"></label>
<html:input
id="__addonRef__-annotationTagContent"
type="text"
class="enable-auto-tag-annotation"
preference="__prefsPrefix__.annotationTagContent"
></html:input>
</hbox>
</vbox>
<vbox>
<checkbox
id="__addonRef__-enablePopup"
Expand Down
5 changes: 4 additions & 1 deletion addon/locale/en-US/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ pref-basic-enableNote =
.label = Show "Add Translation to Note" in Pop-up
pref-basic-enableNoteReplaceMode =
.label = Replace Raw Text When Adding Translation to Note

pref-basic-enableAutoTagAnnotation =
.label = Automatically Tag Annotation After Translation
pref-basic-annotationTagContent =
.value = Tag
pref-audio-autoPlay =
.label = Auto-play Pronunciation
pref-audio-showPlayBtn =
Expand Down
5 changes: 4 additions & 1 deletion addon/locale/it-IT/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ pref-basic-enableNote =
.label = Mostra "Aggiungi traduzione alla nota" nel popup
pref-basic-enableNoteReplaceMode =
.label = Sostituisci il testo d'origine quando aggiungi traduzione alla nota

pref-basic-enableAutoTagAnnotation =
.label = Tagga automaticamente l'annotazione dopo la traduzione
pref-basic-annotationTagContent =
.value = Tag
pref-audio-autoPlay =
.label = Riproduci automaticamente la pronuncia
pref-audio-showPlayBtn =
Expand Down
5 changes: 4 additions & 1 deletion addon/locale/zh-CN/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ pref-basic-enableNote =
.label = 在弹窗中显示“添加翻译至笔记”
pref-basic-enableNoteReplaceMode =
.label = 添加翻译至笔记时替换原始文本

pref-basic-enableAutoTagAnnotation =
.label = 翻译后自动为注释添加标签
pref-basic-annotationTagContent =
.value = 标签
pref-audio-autoPlay =
.label = 自动播放发音
pref-audio-showPlayBtn =
Expand Down
2 changes: 2 additions & 0 deletions addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pref("__prefsPrefix__.attachPaperContext", false);
pref("__prefsPrefix__.enablePopup", true);
pref("__prefsPrefix__.enableComment", false);
pref("__prefsPrefix__.enableAnnotationFromSyncTranslation", false);
pref("__prefsPrefix__.enableAutoTagAnnotation", false);
pref("__prefsPrefix__.annotationTagContent", "");
pref("__prefsPrefix__.annotationTranslationPosition", "comment");
pref("__prefsPrefix__.enableNote", true);
pref("__prefsPrefix__.enableNoteReplaceMode", false);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/defaultPrefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ export function setDefaultPrefSettings() {
setPref(prefKey, String(value));
}
});

if (!getPref("annotationTagContent")) {
setPref("annotationTagContent", isZhCN ? "翻译" : "Translation");
}
}
20 changes: 20 additions & 0 deletions src/modules/preferenceWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ function buildPrefsPane() {
ztoolkit.ExtraField.setExtraField(item, "abstractTranslation", "");
});
});

doc
.querySelector(`#${makeId("enableAutoTagAnnotation")}`)
?.addEventListener("command", (e: Event) => {
onPrefsEvents("setEnableAutoTagAnnotation");
});
}

function updatePrefsPaneDefault() {
Expand All @@ -266,6 +272,7 @@ function updatePrefsPaneDefault() {
onPrefsEvents("setUseWordService", false);
onPrefsEvents("setSentenceSecret", false);
onPrefsEvents("setWordSecret", false);
onPrefsEvents("setEnableAutoTagAnnotation", false);
}

function onPrefsEvents(type: string, fromElement: boolean = true) {
Expand Down Expand Up @@ -336,6 +343,19 @@ function onPrefsEvents(type: string, fromElement: boolean = true) {
}
}
break;
case "setEnableAutoTagAnnotation":
{
const elemValue = fromElement
? (
doc.querySelector(
`#${makeId("enableAutoTagAnnotation")}`,
) as XUL.Checkbox
).checked
: (getPref("enableAutoTagAnnotation") as boolean);
const hidden = !elemValue;
setDisabled("enable-auto-tag-annotation", hidden);
}
break;
case "setSentenceService":
{
setPref(
Expand Down
20 changes: 20 additions & 0 deletions src/modules/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,26 @@ export class TranslationServices {
? "annotationComment"
: "annotationText"
] = text;

// Auto tag
const enableAutoTag = getPref(
"enableAutoTagAnnotation",
) as boolean;
if (enableAutoTag) {
const tagContent = getPref("annotationTagContent") as string;
if (tagContent && tagContent.trim()) {
const tag = tagContent.trim();
// Check if the tag already exists
const existingTags = item.getTags();
const tagExists = existingTags.some(
(existingTag) => existingTag.tag === tag,
);

if (!tagExists) {
item.addTag(tag);
}
}
}
item.saveTx();
}
}
Expand Down
2 changes: 2 additions & 0 deletions typings/i10n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export type FluentMessageId =
| 'pref-advanced-stripEmptyLines'
| 'pref-audio-autoPlay'
| 'pref-audio-showPlayBtn'
| 'pref-basic-annotationTagContent'
| 'pref-basic-annotationTranslationInBody'
| 'pref-basic-annotationTranslationInComment'
| 'pref-basic-enableAnnotationFromSyncTranslation'
| 'pref-basic-enableAuto'
| 'pref-basic-enableAutoTagAnnotation'
| 'pref-basic-enableComment'
| 'pref-basic-enableHidePopupTextarea'
| 'pref-basic-enableNote'
Expand Down
2 changes: 2 additions & 0 deletions typings/prefs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare namespace _ZoteroTypes {
"enablePopup": boolean;
"enableComment": boolean;
"enableAnnotationFromSyncTranslation": boolean;
"enableAutoTagAnnotation": boolean;
"annotationTagContent": string;
"annotationTranslationPosition": string;
"enableNote": boolean;
"enableNoteReplaceMode": boolean;
Expand Down
Loading