mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-09 01:26:24 +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 { Menu, MenuItem } from '@szhsin/react-menu';
|
||||||
import { useState } from 'preact/hooks';
|
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 Icon from './icon';
|
||||||
import TranslationBlock from './translation-block';
|
import TranslationBlock from './translation-block';
|
||||||
|
|
||||||
export default function MediaAltModal({ alt, lang, onClose }) {
|
export default function MediaAltModal({ alt, lang, onClose }) {
|
||||||
|
const snapStates = useSnapshot(states);
|
||||||
const [forceTranslate, setForceTranslate] = useState(false);
|
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 (
|
return (
|
||||||
<div class="sheet">
|
<div class="sheet">
|
||||||
{!!onClose && (
|
{!!onClose && (
|
||||||
|
@ -44,8 +61,12 @@ export default function MediaAltModal({ alt, lang, onClose }) {
|
||||||
>
|
>
|
||||||
{alt}
|
{alt}
|
||||||
</p>
|
</p>
|
||||||
{forceTranslate && (
|
{(differentLanguage || forceTranslate) && (
|
||||||
<TranslationBlock forceTranslate={forceTranslate} text={alt} />
|
<TranslationBlock
|
||||||
|
forceTranslate={forceTranslate}
|
||||||
|
sourceLanguage={lang}
|
||||||
|
text={alt}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -484,7 +484,7 @@ function Status({
|
||||||
};
|
};
|
||||||
|
|
||||||
const differentLanguage =
|
const differentLanguage =
|
||||||
language &&
|
!!language &&
|
||||||
language !== targetLanguage &&
|
language !== targetLanguage &&
|
||||||
!localeMatch([language], [targetLanguage]) &&
|
!localeMatch([language], [targetLanguage]) &&
|
||||||
!contentTranslationHideLanguages.find(
|
!contentTranslationHideLanguages.find(
|
||||||
|
|
Loading…
Reference in a new issue