import React from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import { translateStatus, undoStatusTranslation } from 'soapbox/actions/statuses'; import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks'; import { Stack } from './ui'; import type { Status } from 'soapbox/types/entities'; interface ITranslateButton { status: Status, } const TranslateButton: React.FC = ({ status }) => { const dispatch = useAppDispatch(); const intl = useIntl(); const features = useFeatures(); const me = useAppSelector((state) => state.me); const renderTranslate = /* translationEnabled && */ me && ['public', 'unlisted'].includes(status.visibility) && status.contentHtml.length > 0 && status.language !== null && intl.locale !== status.language; const handleTranslate: React.MouseEventHandler = (e) => { e.stopPropagation(); if (status.translation) { dispatch(undoStatusTranslation(status.id)); } else { dispatch(translateStatus(status.id, intl.locale)); } }; if (!features.translations || !renderTranslate) return null; if (status.translation) { const languageNames = new Intl.DisplayNames([intl.locale], { type: 'language' }); const languageName = languageNames.of(status.language!); const provider = status.translation.get('provider'); return ( ); } return ( ); }; export default TranslateButton;