mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 02:42:27 +08:00
feat(note_language): set language attribute for note
This commit is contained in:
parent
dbea35f9f3
commit
bccfeed431
@ -4,6 +4,7 @@ import { getAvailableLocales, type Locale } from "../services/i18n.js";
|
|||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
import type { EventData } from "../components/app_context.js";
|
import type { EventData } from "../components/app_context.js";
|
||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
|
import attributes from "../services/attributes.js";
|
||||||
|
|
||||||
const TPL = `\
|
const TPL = `\
|
||||||
<div class="dropdown note-language-widget">
|
<div class="dropdown note-language-widget">
|
||||||
@ -54,7 +55,11 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
|
|||||||
const $link = $('<a class="dropdown-item">')
|
const $link = $('<a class="dropdown-item">')
|
||||||
.attr("data-language", locale.id)
|
.attr("data-language", locale.id)
|
||||||
.append('<span class="check">✓</span> ')
|
.append('<span class="check">✓</span> ')
|
||||||
.append($title);
|
.append($title)
|
||||||
|
.on("click", () => {
|
||||||
|
const languageId = $link.attr("data-language") ?? "";
|
||||||
|
this.save(languageId);
|
||||||
|
})
|
||||||
this.$noteLanguageDropdown.append($link);
|
this.$noteLanguageDropdown.append($link);
|
||||||
} else {
|
} else {
|
||||||
this.$noteLanguageDropdown.append('<div class="dropdown-divider"></div>');
|
this.$noteLanguageDropdown.append('<div class="dropdown-divider"></div>');
|
||||||
@ -62,6 +67,16 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async save(languageId: string) {
|
||||||
|
if (!this.note) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (languageId) {
|
||||||
|
attributes.setLabel(this.note.noteId, "language", languageId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async refreshWithNote(note: FNote) {
|
async refreshWithNote(note: FNote) {
|
||||||
this.$noteLanguageDesc.text(t("note_language.not_set"));
|
this.$noteLanguageDesc.text(t("note_language.not_set"));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user