kopia lustrzana https://github.com/cheeaun/phanpy
Auto-translate alt text if short
rodzic
faf7ee4011
commit
a42a84cc23
|
@ -1,6 +1,6 @@
|
|||
import { Trans, useLingui } from '@lingui/react/macro';
|
||||
import { Menu, MenuItem } from '@szhsin/react-menu';
|
||||
import { useState } from 'preact/hooks';
|
||||
import { useEffect, useState } from 'preact/hooks';
|
||||
import { useSnapshot } from 'valtio';
|
||||
|
||||
import getTranslateTargetLanguage from '../utils/get-translate-target-language';
|
||||
|
@ -12,6 +12,8 @@ import Icon from './icon';
|
|||
import Menu2 from './menu2';
|
||||
import TranslationBlock from './translation-block';
|
||||
|
||||
const FORCE_TRANSLATE_LIMIT = 140;
|
||||
|
||||
export default function MediaAltModal({ alt, lang, onClose }) {
|
||||
const { t } = useLingui();
|
||||
const snapStates = useSnapshot(states);
|
||||
|
@ -27,6 +29,13 @@ export default function MediaAltModal({ alt, lang, onClose }) {
|
|||
(l) => lang === l || localeMatch([lang], [l]),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const isShortAlt = alt?.length > 0 && alt?.length <= FORCE_TRANSLATE_LIMIT;
|
||||
if (differentLanguage && isShortAlt) {
|
||||
setForceTranslate(true);
|
||||
}
|
||||
}, [differentLanguage, alt]);
|
||||
|
||||
return (
|
||||
<div class="sheet" tabindex="-1">
|
||||
{!!onClose && (
|
||||
|
|
|
@ -109,7 +109,7 @@ msgstr ""
|
|||
#: src/components/account-info.jsx:457
|
||||
#: src/components/account-info.jsx:1231
|
||||
#: src/components/compose.jsx:2776
|
||||
#: src/components/media-alt-modal.jsx:46
|
||||
#: src/components/media-alt-modal.jsx:55
|
||||
#: src/components/media-modal.jsx:359
|
||||
#: src/components/status.jsx:1818
|
||||
#: src/components/status.jsx:1835
|
||||
|
@ -459,7 +459,7 @@ msgstr ""
|
|||
#: src/components/generic-accounts.jsx:151
|
||||
#: src/components/keyboard-shortcuts-help.jsx:43
|
||||
#: src/components/list-add-edit.jsx:37
|
||||
#: src/components/media-alt-modal.jsx:34
|
||||
#: src/components/media-alt-modal.jsx:43
|
||||
#: src/components/media-modal.jsx:323
|
||||
#: src/components/notification-service.jsx:157
|
||||
#: src/components/report-modal.jsx:75
|
||||
|
@ -1298,19 +1298,19 @@ msgstr ""
|
|||
msgid "Posts on this list are hidden from Home/Following"
|
||||
msgstr "Posts on this list are hidden from Home/Following"
|
||||
|
||||
#: src/components/media-alt-modal.jsx:39
|
||||
#: src/components/media-alt-modal.jsx:48
|
||||
#: src/components/media.jsx:51
|
||||
msgid "Media description"
|
||||
msgstr ""
|
||||
|
||||
#: src/components/media-alt-modal.jsx:58
|
||||
#: src/components/media-alt-modal.jsx:67
|
||||
#: src/components/status.jsx:1131
|
||||
#: src/components/status.jsx:1140
|
||||
#: src/components/translation-block.jsx:237
|
||||
msgid "Translate"
|
||||
msgstr ""
|
||||
|
||||
#: src/components/media-alt-modal.jsx:69
|
||||
#: src/components/media-alt-modal.jsx:78
|
||||
#: src/components/status.jsx:1159
|
||||
msgid "Speak"
|
||||
msgstr ""
|
||||
|
|
Ładowanie…
Reference in New Issue