feat: Automatically detect and warn to correct the language of post
This commit is contained in:
parent
605e97181b
commit
872ea8adb0
7 changed files with 47 additions and 1 deletions
|
@ -2227,3 +2227,5 @@ moreUrlsDescription: "Enter the pages you want to pin to the help menu in the lo
|
||||||
left corner using this notation:\n\"Display name\": https://example.com/"
|
left corner using this notation:\n\"Display name\": https://example.com/"
|
||||||
messagingUnencryptedInfo: "Chats on Firefish are not end-to-end encrypted. Don't share
|
messagingUnencryptedInfo: "Chats on Firefish are not end-to-end encrypted. Don't share
|
||||||
any sensitive infomation over Firefish."
|
any sensitive infomation over Firefish."
|
||||||
|
autocorrectNoteLanguage: Automatically detect and warn to correct the language of your post.
|
||||||
|
incorrectLanguageWarning: "It looks like your post is in {detected}, but the language you selected is {current}.\nWould you like to post in {detected} instead?"
|
||||||
|
|
|
@ -2056,3 +2056,5 @@ searchRangeDescription: "如果您要过滤时间段,请按以下格式输入
|
||||||
messagingUnencryptedInfo: "Firefish 上的聊天没有经过端到端加密,请不要在聊天中分享您的敏感信息。"
|
messagingUnencryptedInfo: "Firefish 上的聊天没有经过端到端加密,请不要在聊天中分享您的敏感信息。"
|
||||||
noAltTextWarning: 有些附件没有描述。您是否忘记写描述了?
|
noAltTextWarning: 有些附件没有描述。您是否忘记写描述了?
|
||||||
showNoAltTextWarning: 当您尝试发布没有描述的帖子附件时显示警告
|
showNoAltTextWarning: 当您尝试发布没有描述的帖子附件时显示警告
|
||||||
|
autocorrectNoteLanguage: 自动检测和弹窗纠正您所使用的帖子语言
|
||||||
|
incorrectLanguageWarning: "看上去您帖子使用的语言是{detected},但您选择的语言是{current}。\n要改为以{detected}发帖吗?"
|
||||||
|
|
|
@ -1020,6 +1020,37 @@ function deleteDraft() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function post() {
|
async function post() {
|
||||||
|
// For text that is too short, the false positive rate may be too high, so we don't show alarm.
|
||||||
|
if (defaultStore.state.autocorrectNoteLanguage && text.value.length > 10) {
|
||||||
|
const detectedLanguage: string = detectLanguage(text.value) ?? "";
|
||||||
|
|
||||||
|
const currentLanguageName : string | undefined | false =
|
||||||
|
language.value &&
|
||||||
|
langmap[language.value]?.nativeName
|
||||||
|
const detectedLanguageName : string | undefined | false =
|
||||||
|
detectedLanguage !== "" &&
|
||||||
|
detectedLanguage !== language.value &&
|
||||||
|
langmap[detectedLanguage]?.nativeName;
|
||||||
|
|
||||||
|
if (currentLanguageName && detectedLanguageName) {
|
||||||
|
// "canceled" means "post with detected language".
|
||||||
|
const { canceled } = await os.confirm({
|
||||||
|
type: "warning",
|
||||||
|
text: i18n.t("incorrectLanguageWarning", {
|
||||||
|
detected: `${detectedLanguageName}`,
|
||||||
|
current: `${currentLanguageName}`,
|
||||||
|
}),
|
||||||
|
okText: i18n.ts.no,
|
||||||
|
cancelText: i18n.ts.yes,
|
||||||
|
isPlaintext: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (canceled) {
|
||||||
|
language.value = detectedLanguage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
defaultStore.state.showNoAltTextWarning &&
|
defaultStore.state.showNoAltTextWarning &&
|
||||||
files.value.some((f) => f.comment == null || f.comment.length === 0)
|
files.value.some((f) => f.comment == null || f.comment.length === 0)
|
||||||
|
|
|
@ -22,7 +22,7 @@ class I18n<T extends Record<string, any>> {
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
for (const [k, v] of Object.entries(args)) {
|
for (const [k, v] of Object.entries(args)) {
|
||||||
str = str.replace(`{${k}}`, v.toString());
|
str = str.replaceAll(`{${k}}`, v.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
|
|
@ -124,6 +124,9 @@
|
||||||
<FormSwitch v-model="showNoAltTextWarning" class="_formBlock">{{
|
<FormSwitch v-model="showNoAltTextWarning" class="_formBlock">{{
|
||||||
i18n.ts.showNoAltTextWarning
|
i18n.ts.showNoAltTextWarning
|
||||||
}}</FormSwitch>
|
}}</FormSwitch>
|
||||||
|
<FormSwitch v-model="autocorrectNoteLanguage" class="_formBlock">{{
|
||||||
|
i18n.ts.autocorrectNoteLanguage
|
||||||
|
}}</FormSwitch>
|
||||||
|
|
||||||
<FormSelect v-model="serverDisconnectedBehavior" class="_formBlock">
|
<FormSelect v-model="serverDisconnectedBehavior" class="_formBlock">
|
||||||
<template #label>{{ i18n.ts.whenServerDisconnected }}</template>
|
<template #label>{{ i18n.ts.whenServerDisconnected }}</template>
|
||||||
|
@ -530,6 +533,9 @@ const pullToRefreshThreshold = computed(
|
||||||
const showNoAltTextWarning = computed(
|
const showNoAltTextWarning = computed(
|
||||||
defaultStore.makeGetterSetter("showNoAltTextWarning"),
|
defaultStore.makeGetterSetter("showNoAltTextWarning"),
|
||||||
);
|
);
|
||||||
|
const autocorrectNoteLanguage = computed(
|
||||||
|
defaultStore.makeGetterSetter("autocorrectNoteLanguage"),
|
||||||
|
);
|
||||||
|
|
||||||
// This feature (along with injectPromo) is currently disabled
|
// This feature (along with injectPromo) is currently disabled
|
||||||
// function onChangeInjectFeaturedNote(v) {
|
// function onChangeInjectFeaturedNote(v) {
|
||||||
|
|
|
@ -125,6 +125,7 @@ const defaultStoreSaveKeys: (keyof (typeof defaultStore)["state"])[] = [
|
||||||
"enablePullToRefresh",
|
"enablePullToRefresh",
|
||||||
"pullToRefreshThreshold",
|
"pullToRefreshThreshold",
|
||||||
"showNoAltTextWarning",
|
"showNoAltTextWarning",
|
||||||
|
"autocorrectNoteLanguage",
|
||||||
];
|
];
|
||||||
const coldDeviceStorageSaveKeys: (keyof typeof ColdDeviceStorage.default)[] = [
|
const coldDeviceStorageSaveKeys: (keyof typeof ColdDeviceStorage.default)[] = [
|
||||||
"lightTheme",
|
"lightTheme",
|
||||||
|
|
|
@ -432,6 +432,10 @@ export const defaultStore = markRaw(
|
||||||
where: "account",
|
where: "account",
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
autocorrectNoteLanguage: {
|
||||||
|
where: "account",
|
||||||
|
default: true,
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue