add option to put Translate button in the note toolbar
This commit is contained in:
parent
f869bdfc4e
commit
2fdec0ce29
13 changed files with 128 additions and 42 deletions
|
|
@ -176,7 +176,7 @@ function getNoteEmbedCodeMenu(note: Misskey.entities.Note, text: string): MenuIt
|
|||
|
||||
export function getNoteMenu(props: {
|
||||
note: Misskey.entities.Note;
|
||||
translation: Ref<Misskey.entities.NotesTranslateResponse | null>;
|
||||
translation: Ref<Misskey.entities.NotesTranslateResponse | false | null>;
|
||||
translating: Ref<boolean>;
|
||||
isDeleted: Ref<boolean>;
|
||||
currentClip?: Misskey.entities.Clip;
|
||||
|
|
@ -290,17 +290,6 @@ export function getNoteMenu(props: {
|
|||
os.pageWindow(`/notes/${appearNote.id}`);
|
||||
}
|
||||
|
||||
async function translate(): Promise<void> {
|
||||
if (props.translation.value != null) return;
|
||||
props.translating.value = true;
|
||||
props.translation.value = await misskeyApi('notes/translate', {
|
||||
noteId: appearNote.id,
|
||||
targetLang: miLocalStorage.getItem('lang') ?? navigator.language,
|
||||
}).finally(() => {
|
||||
props.translating.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
const menuItems: MenuItem[] = [];
|
||||
|
||||
if ($i) {
|
||||
|
|
@ -357,7 +346,7 @@ export function getNoteMenu(props: {
|
|||
menuItems.push({
|
||||
icon: 'ti ti-language-hiragana',
|
||||
text: i18n.ts.translate,
|
||||
action: translate,
|
||||
action: () => translateNote(appearNote.id, props.translation, props.translating),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -697,3 +686,20 @@ export function getRenoteMenu(props: {
|
|||
menu: renoteItems,
|
||||
};
|
||||
}
|
||||
|
||||
export async function translateNote(noteId: string, translation: Ref<Misskey.entities.NotesTranslateResponse | false | null>, translating: Ref<boolean>): Promise<void> {
|
||||
if (translating.value || translation.value) return;
|
||||
translating.value = true;
|
||||
try {
|
||||
const targetLang = miLocalStorage.getItem('lang') ?? navigator.language;
|
||||
translation.value = await misskeyApi('notes/translate', {
|
||||
noteId,
|
||||
targetLang,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`Translation failed for ${noteId}: `, err);
|
||||
translation.value = false;
|
||||
} finally {
|
||||
translating.value = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue