diff --git a/src/components/Post/Translated/index.tsx b/src/components/Post/Translated/index.tsx index 3730796294..9dccf0b3d7 100644 --- a/src/components/Post/Translated/index.tsx +++ b/src/components/Post/Translated/index.tsx @@ -1,5 +1,5 @@ import {useCallback, useMemo} from 'react' -import {Platform, View} from 'react-native' +import {type GestureResponderEvent, Platform, View} from 'react-native' import {type AppBskyFeedDefs} from '@atproto/api' import {Trans, useLingui} from '@lingui/react/macro' @@ -9,20 +9,23 @@ import {useTranslate} from '#/lib/translation' import {type TranslationFunction} from '#/lib/translation/types' import { codeToLanguageName, + getTranslatorLink, isPostInLanguage, languageName, } from '#/locale/helpers' import {LANGUAGES} from '#/locale/languages' import {useLanguagePrefs} from '#/state/preferences' -import {atoms as a, native, useTheme} from '#/alf' +import {atoms as a, native, useTheme, web} from '#/alf' import {Button} from '#/components/Button' import {ArrowRight_Stroke2_Corner0_Rounded as ArrowRightIcon} from '#/components/icons/Arrow' import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times' import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning' +import {Link} from '#/components/Link' import {Loader} from '#/components/Loader' import * as Select from '#/components/Select' import {Text} from '#/components/Typography' import {useAnalytics} from '#/analytics' +import {IS_WEB} from '#/env' export function TranslatedPost({ post, @@ -108,18 +111,25 @@ function TranslationLink({ const {t: l} = useLingui() const ax = useAnalytics() - const handleTranslate = useCallback(() => { - void translate({ - text: postText, - targetLangCode: primaryLanguage, - }) + const handleTranslate = useCallback( + (evt: GestureResponderEvent) => { + evt.preventDefault() - ax.metric('translate', { - sourceLanguages: [], - targetLanguage: primaryLanguage, - textLength: postText.length, - }) - }, [ax, postText, primaryLanguage, translate]) + void translate({ + text: postText, + targetLangCode: primaryLanguage, + }) + + ax.metric('translate', { + sourceLanguages: [], + targetLanguage: primaryLanguage, + textLength: postText.length, + }) + + return false + }, + [ax, postText, primaryLanguage, translate], + ) return ( - + ) } @@ -159,6 +174,14 @@ function TranslationError({ const {t: l} = useLingui() const translate = useGoogleTranslate() + const handleFallback = (evt: GestureResponderEvent) => { + evt.preventDefault() + + void translate(postText, primaryLanguage) + + return false + } + return ( - + )