feat: ability to set translation target language

This commit is contained in:
naskya 2023-08-01 02:21:56 +09:00
parent dc71efe43c
commit 1a40218b9b
Signed by: naskya
GPG key ID: 164DFF24E2D40139
7 changed files with 37 additions and 5 deletions

View file

@ -10,6 +10,7 @@
## 主要な変更点
- UI 用の言語とは別に、投稿翻訳に使用する言語を設定可能に
- 投稿言語を自動検出して外国語の投稿に翻訳ボタンを表示する設定を追加
- モバイル表示の下部のウィジェットボタンを再読み込みボタンに変更可能に
- スマートフォンでウィジェットは使わないけど再読み込みはたくさんする人はいそう

View file

@ -1143,6 +1143,7 @@ delete2faConfirm: "This will irreversibly delete 2FA on this account. Proceed?"
deletePasskeysConfirm: "This will irreversibly delete all passkeys and security keys on this account. Proceed?"
inputNotMatch: "Input does not match"
detectPostLanguage: "Automatically detect the language and show a translate button for non-English posts"
languageForTranslation: "Language used for post translation"
_sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing

View file

@ -996,6 +996,7 @@ replaceChatButtonWithAccountButton: "画面下部のチャットのボタンを
replaceWidgetsButtonWithReloadButton: "画面下部のウィジェットのボタンを再読み込みボタンに変更する"
addRe: "閲覧注意の投稿への返信で、注釈の先頭に\"re:\"を追加する"
detectPostLanguage: "投稿の言語を自動検出し、外国語の投稿に翻訳ボタンを表示する"
languageForTranslation: "投稿翻訳に使用する言語"
_sensitiveMediaDetection:
description: "機械学習を使って自動でセンシティブなメディアを検出し、モデレーションに役立てられます。サーバーの負荷が少し増えます。"

View file

@ -374,7 +374,9 @@ const isForeignLanguage = (() => {
const text = purifyMFM(appearNote.text).trim();
if (!text) return false;
const uiLanguage = (
localStorage.getItem("lang") || navigator.language
localStorage.getItem("translateLang") ||
localStorage.getItem("lang") ||
navigator.language
).slice(0, 2);
return detectLanguage(text) !== uiLanguage;
})();
@ -383,7 +385,10 @@ const translate = async () => {
translating.value = true;
translation.value = await os.api("notes/translate", {
noteId: appearNote.id,
targetLang: localStorage.getItem("lang") || navigator.language,
targetLang:
localStorage.getItem("translateLang") ||
localStorage.getItem("lang") ||
navigator.language,
});
translating.value = false;
};

View file

@ -290,7 +290,9 @@ const isForeignLanguage = (() => {
const text = purifyMFM(appearNote.text).trim();
if (!text) return false;
const uiLanguage = (
localStorage.getItem("lang") || navigator.language
localStorage.getItem("translateLang") ||
localStorage.getItem("lang") ||
navigator.language
).slice(0, 2);
return detectLanguage(text) !== uiLanguage;
})();
@ -299,7 +301,10 @@ const translate = async () => {
translating.value = true;
translation.value = await os.api("notes/translate", {
noteId: appearNote.id,
targetLang: localStorage.getItem("lang") || navigator.language,
targetLang:
localStorage.getItem("translateLang") ||
localStorage.getItem("lang") ||
navigator.language,
});
translating.value = false;
};

View file

@ -17,6 +17,16 @@
</template>
</FormSelect>
<FormSelect v-model="translateLang" class="_formBlock">
<template #label>
{{ i18n.ts.languageForTranslation }}
<span class="_beta">{{ i18n.ts.originalFeature }}</span>
</template>
<option v-for="x in langs" :key="x[0]" :value="x[0]">
{{ x[1] }}
</option>
</FormSelect>
<FormRadios v-model="overridedDeviceKind" class="_formBlock">
<template #label>{{ i18n.ts.overridedDeviceKind }}</template>
<option :value="null">{{ i18n.ts.auto }}</option>
@ -314,6 +324,7 @@ import { definePageMetadata } from "@/scripts/page-metadata";
import { deviceKind } from "@/scripts/device-kind";
const lang = ref(localStorage.getItem("lang"));
const translateLang = ref(localStorage.getItem("translateLang"));
const fontSize = ref(localStorage.getItem("fontSize"));
const useSystemFont = ref(localStorage.getItem("useSystemFont") != null);
@ -431,6 +442,10 @@ watch(lang, () => {
localStorage.removeItem("locale");
});
watch(translateLang, () => {
localStorage.setItem("translateLang", translateLang.value as string);
});
watch(fontSize, () => {
if (fontSize.value == null) {
localStorage.removeItem("fontSize");
@ -450,6 +465,7 @@ watch(useSystemFont, () => {
watch(
[
lang,
translateLang,
fontSize,
useSystemFont,
enableInfiniteScroll,

View file

@ -241,7 +241,10 @@ export function getNoteMenu(props: {
props.translating.value = true;
const res = await os.api("notes/translate", {
noteId: appearNote.id,
targetLang: localStorage.getItem("lang") || navigator.language,
targetLang:
localStorege.getItem("translateLang") ||
localStorage.getItem("lang") ||
navigator.language,
});
props.translating.value = false;
props.translation.value = res;