mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 14:16:39 +01:00
Show Translate button when different lang inside alt modal
This commit is contained in:
parent
baa2605d27
commit
49fdcf7837
2 changed files with 24 additions and 3 deletions
|
@ -1,11 +1,28 @@
|
|||
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 states from '../utils/states';
|
||||
|
||||
import Icon from './icon';
|
||||
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">
|
||||
{!!onClose && (
|
||||
|
@ -44,8 +61,12 @@ export default function MediaAltModal({ alt, lang, onClose }) {
|
|||
>
|
||||
{alt}
|
||||
</p>
|
||||
{forceTranslate && (
|
||||
<TranslationBlock forceTranslate={forceTranslate} text={alt} />
|
||||
{(differentLanguage || forceTranslate) && (
|
||||
<TranslationBlock
|
||||
forceTranslate={forceTranslate}
|
||||
sourceLanguage={lang}
|
||||
text={alt}
|
||||
/>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
|
|
|
@ -484,7 +484,7 @@ function Status({
|
|||
};
|
||||
|
||||
const differentLanguage =
|
||||
language &&
|
||||
!!language &&
|
||||
language !== targetLanguage &&
|
||||
!localeMatch([language], [targetLanguage]) &&
|
||||
!contentTranslationHideLanguages.find(
|
||||
|
|
Loading…
Reference in a new issue