mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-12-29 21:58:14 +03:00
c2e6d732c4
Expecting bugs!
94 lines
2.7 KiB
JavaScript
94 lines
2.7 KiB
JavaScript
import { t, Trans } from '@lingui/macro';
|
|
import { Menu, MenuItem } from '@szhsin/react-menu';
|
|
import { useState } from 'preact/hooks';
|
|
import { useSnapshot } from 'valtio';
|
|
|
|
import getTranslateTargetLanguage from '../utils/get-translate-target-language';
|
|
import localeMatch from '../utils/locale-match';
|
|
import { speak, supportsTTS } from '../utils/speech';
|
|
import states from '../utils/states';
|
|
|
|
import Icon from './icon';
|
|
import Menu2 from './menu2';
|
|
import TranslationBlock from './translation-block';
|
|
|
|
export default function MediaAltModal({ alt, lang, onClose }) {
|
|
const snapStates = useSnapshot(states);
|
|
const [forceTranslate, setForceTranslate] = useState(false);
|
|
const targetLanguage = getTranslateTargetLanguage(true);
|
|
const contentTranslationHideLanguages =
|
|
snapStates.settings.contentTranslationHideLanguages || [];
|
|
const differentLanguage =
|
|
!!lang &&
|
|
lang !== targetLanguage &&
|
|
!localeMatch([lang], [targetLanguage]) &&
|
|
!contentTranslationHideLanguages.find(
|
|
(l) => lang === l || localeMatch([lang], [l]),
|
|
);
|
|
|
|
return (
|
|
<div class="sheet" tabindex="-1">
|
|
{!!onClose && (
|
|
<button type="button" class="sheet-close outer" onClick={onClose}>
|
|
<Icon icon="x" alt={t`Close`} />
|
|
</button>
|
|
)}
|
|
<header class="header-grid">
|
|
<h2>
|
|
<Trans>Media description</Trans>
|
|
</h2>
|
|
<div class="header-side">
|
|
<Menu2
|
|
align="end"
|
|
menuButton={
|
|
<button type="button" class="plain4">
|
|
<Icon icon="more" alt={t`More`} size="xl" />
|
|
</button>
|
|
}
|
|
>
|
|
<MenuItem
|
|
disabled={forceTranslate}
|
|
onClick={() => {
|
|
setForceTranslate(true);
|
|
}}
|
|
>
|
|
<Icon icon="translate" />
|
|
<span>
|
|
<Trans>Translate</Trans>
|
|
</span>
|
|
</MenuItem>
|
|
{supportsTTS && (
|
|
<MenuItem
|
|
onClick={() => {
|
|
speak(alt, lang);
|
|
}}
|
|
>
|
|
<Icon icon="speak" />
|
|
<span>
|
|
<Trans>Speak</Trans>
|
|
</span>
|
|
</MenuItem>
|
|
)}
|
|
</Menu2>
|
|
</div>
|
|
</header>
|
|
<main lang={lang} dir="auto">
|
|
<p
|
|
style={{
|
|
whiteSpace: 'pre-wrap',
|
|
textWrap: 'pretty',
|
|
}}
|
|
>
|
|
{alt}
|
|
</p>
|
|
{(differentLanguage || forceTranslate) && (
|
|
<TranslationBlock
|
|
forceTranslate={forceTranslate}
|
|
sourceLanguage={lang}
|
|
text={alt}
|
|
/>
|
|
)}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|