Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 引用や返信のノートすべてに翻訳ボタンが表示される #598

Merged
merged 3 commits into from
Dec 26, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG_YOJO.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ xxxx-xx-xx
- Fix: ノート詳細画面でリアクション出来ない [#584](https://github.com/yojo-art/cherrypick/pull/584)
- Fix: タイムラインオプションで表示有無選択の選択肢を修正 [#590](https://github.com/yojo-art/cherrypick/pull/590)
- Fix: MFMチートシートが表示できない不具合を修正 [#592](https://github.com/yojo-art/cherrypick/pull/592)
- Fix: 引用や返信のノートすべてに翻訳ボタンが表示される [#598](https://github.com/yojo-art/cherrypick/pull/598)

### Server
- Fix:`api/ap/fetch-outbox`でリノートしか取得されないのを修正 [#588](https://github.com/yojo-art/cherrypick/pull/588)
Expand Down
30 changes: 23 additions & 7 deletions packages/frontend/src/components/MkSubNoteContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ SPDX-License-Identifier: AGPL-3.0-only
:enableAnimatedMfm="enableAnimatedMfm"
/>
<MkA v-if="note.renoteId" :class="$style.rp" :to="`/notes/${note.renoteId}`">RN: ...</MkA>
<div v-if="defaultStore.state.showTranslateButtonInNote && (!defaultStore.state.useAutoTranslate || (!$i.policies.canUseAutoTranslate || (defaultStore.state.useAutoTranslate && (isLong || note.cw != null || !showContent)))) && instance.translatorAvailable && $i && $i.policies.canUseTranslator && note.text && isForeignLanguage && !note.isSchedule" style="padding-top: 5px; color: var(--MI_THEME-accent);">
<div v-if="defaultStore.state.showTranslateButtonInNote && (!defaultStore.state.useAutoTranslate || (!$i.policies.canUseAutoTranslate || (defaultStore.state.useAutoTranslate && (isLong || note.cw != null || !showContent)))) && instance.translatorAvailable && $i && $i.policies.canUseTranslator && (note.text || note.poll) && isForeignLanguage" style="padding-top: 5px; color: var(--MI_THEME-accent);">
<button v-if="!(translating || translation)" ref="translateButton" class="_button" @click.stop="translate()">{{ i18n.ts.translateNote }}</button>
<button v-else class="_button" @click.stop="translation = null">{{ i18n.ts.close }}</button>
</div>
<div v-if="translating || translation" :class="$style.translation">
<MkLoading v-if="translating" mini/>
<div v-else-if="translation">
<b>{{ i18n.tsx.translatedFrom({ x: translation.sourceLang }) }}:</b><hr style="margin: 10px 0;">
<Mfm
<Mfm v-if="note.text"
:text="translation.text"
:author="note.user"
:nyaize="defaultStore.state.disableNyaize || noNyaize ? false : 'respect'"
Expand Down Expand Up @@ -459,12 +459,19 @@ async function clip(): Promise<void> {
os.popupMenu(await getNoteClipMenu({ note: note.value, isDeleted, currentClip: currentClip?.value }), clipButton.value).then(focus);
}

const isForeignLanguage: boolean = note.value.text != null && (() => {
const isForeignLanguage: boolean = (note.value.text != null || note.value.poll != null) && (() => {
const targetLang = (miLocalStorage.getItem('lang') ?? navigator.language).slice(0, 2);
const postLang = detectLanguage(note.value.text);
const choicesLang = note.value.poll?.choices.map((choice) => choice.text).join(' ') ?? '';
const pollLang = detectLanguage(choicesLang);
return postLang !== '' && (postLang !== targetLang || pollLang !== targetLang);
if (note.value.text) {
const postLang = detectLanguage(note.value.text);
if (postLang !== '' && postLang !== targetLang) return true;
}
if (note.value.poll) {
const foreignLang = note.value.poll.choices
.map((choice) => detectLanguage(choice.text))
.filter((lang) => lang !== targetLang).length;
if (0 < foreignLang) return true;
}
return false;
})();

if (defaultStore.state.useAutoTranslate && instance.translatorAvailable && $i.policies.canUseTranslator && $i.policies.canUseAutoTranslate && !isLong && (note.value.cw == null || showContent.value) && note.value.text && isForeignLanguage) translate();
Expand All @@ -474,6 +481,15 @@ async function translate(): Promise<void> {
collapsed.value = false;
translating.value = true;

if (note.value.text == null) {
translating.value = false;
translation.value = {
sourceLang: '',
text: '',
};
return;
}

vibrate(defaultStore.state.vibrateSystem ? 5 : []);

if (props.mock) {
Expand Down
Loading