From 116784463ae05677a130b40fe3b85b42646461b4 Mon Sep 17 00:00:00 2001 From: DS Boyce <260543580+ds-boyce@users.noreply.github.com> Date: Tue, 3 Mar 2026 11:38:22 -0800 Subject: [PATCH] Update option name to forceGoogleTranslate --- src/components/Post/Translated/index.tsx | 10 +-- .../PostControls/PostMenu/PostMenuItems.tsx | 19 +++--- .../PostControls/PostMenu/index.tsx | 6 +- src/components/PostControls/index.tsx | 14 ++-- src/lib/translation/context.ts | 19 +++--- src/lib/translation/index.tsx | 28 ++++---- src/lib/translation/index.web.tsx | 23 ++++--- src/lib/translation/types.ts | 7 -- .../components/ThreadItemAnchor.tsx | 9 +-- .../PostThread/components/ThreadItemPost.tsx | 1 + .../components/ThreadItemTreePost.tsx | 1 + src/screens/VideoFeed/index.tsx | 68 ++++++++----------- src/view/com/post/Post.tsx | 5 +- 13 files changed, 98 insertions(+), 112 deletions(-) diff --git a/src/components/Post/Translated/index.tsx b/src/components/Post/Translated/index.tsx index 4d3162cdc6..66489f47db 100644 --- a/src/components/Post/Translated/index.tsx +++ b/src/components/Post/Translated/index.tsx @@ -148,12 +148,12 @@ function TranslationLanguageSelect({ sourceLanguage: sourceLangCode, targetLanguage: langPrefs.primaryLanguage, }) - void translate( - translationKey, - postText, - langPrefs.primaryLanguage, + void translate({ + key: translationKey, + text: postText, + targetLangCode: langPrefs.primaryLanguage, sourceLangCode, - ) + }) } return ( diff --git a/src/components/PostControls/PostMenu/PostMenuItems.tsx b/src/components/PostControls/PostMenu/PostMenuItems.tsx index 4c94d28f85..58b51bfa4c 100644 --- a/src/components/PostControls/PostMenu/PostMenuItems.tsx +++ b/src/components/PostControls/PostMenu/PostMenuItems.tsx @@ -106,7 +106,7 @@ let PostMenuItems = ({ threadgateRecord, onShowLess, logContext, - googleTranslate, + forceGoogleTranslate, }: { testID: string post: Shadow @@ -121,7 +121,7 @@ let PostMenuItems = ({ threadgateRecord?: AppBskyFeedThreadgate.Record onShowLess?: (interaction: AppBskyFeedDefs.Interaction) => void logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' - googleTranslate: boolean + forceGoogleTranslate: boolean }): React.ReactNode => { const {hasSession, currentAccount} = useSession() const {t: l} = useLingui() @@ -258,15 +258,12 @@ let PostMenuItems = ({ } const onPressTranslate = () => { - void translate( - translationKey, - record.text, - langPrefs.primaryLanguage, - undefined, - { - googleTranslate, - }, - ) + void translate({ + key: translationKey, + text: record.text, + targetLangCode: langPrefs.primaryLanguage, + forceGoogleTranslate, + }) if ( bsky.dangerousIsType( diff --git a/src/components/PostControls/PostMenu/index.tsx b/src/components/PostControls/PostMenu/index.tsx index ff4bf167b1..7ed620bd64 100644 --- a/src/components/PostControls/PostMenu/index.tsx +++ b/src/components/PostControls/PostMenu/index.tsx @@ -29,7 +29,7 @@ let PostMenuButton = ({ onShowLess, hitSlop, logContext, - googleTranslate, + forceGoogleTranslate, }: { testID: string post: Shadow @@ -43,7 +43,7 @@ let PostMenuButton = ({ onShowLess?: (interaction: AppBskyFeedDefs.Interaction) => void hitSlop?: Insets logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' - googleTranslate: boolean + forceGoogleTranslate: boolean }): React.ReactNode => { const {t: l} = useLingui() @@ -91,7 +91,7 @@ let PostMenuButton = ({ threadgateRecord={threadgateRecord} onShowLess={onShowLess} logContext={logContext} - googleTranslate={googleTranslate} + forceGoogleTranslate={forceGoogleTranslate} /> )} diff --git a/src/components/PostControls/index.tsx b/src/components/PostControls/index.tsx index b915174121..43f99b5979 100644 --- a/src/components/PostControls/index.tsx +++ b/src/components/PostControls/index.tsx @@ -55,7 +55,7 @@ let PostControls = ({ onShowLess, viaRepost, variant, - googleTranslate = true, + forceGoogleTranslate = false, }: { big?: boolean post: Shadow @@ -71,7 +71,7 @@ let PostControls = ({ onShowLess?: (interaction: AppBskyFeedDefs.Interaction) => void viaRepost?: {uri: string; cid: string} variant?: 'compact' | 'normal' | 'large' - googleTranslate?: boolean + forceGoogleTranslate?: boolean }): React.ReactNode => { const ax = useAnalytics() const {t: l} = useLingui() @@ -125,7 +125,8 @@ let PostControls = ({ } else { await queueUnlike() } - } catch (e: any) { + } catch (err) { + const e = err as Error if (e?.name !== 'AbortError') { throw e } @@ -150,7 +151,8 @@ let PostControls = ({ } else { await queueUnrepost() } - } catch (e: any) { + } catch (err) { + const e = err as Error if (e?.name !== 'AbortError') { throw e } @@ -252,7 +254,7 @@ let PostControls = ({ void onRepost()} onQuote={onQuote} big={big} embeddingDisabled={Boolean(post.viewer?.embeddingDisabled)} @@ -337,7 +339,7 @@ let PostControls = ({ left: secondaryControlSpacingStyles.gap / 2, }} logContext={logContext} - googleTranslate={googleTranslate} + forceGoogleTranslate={forceGoogleTranslate} /> diff --git a/src/lib/translation/context.ts b/src/lib/translation/context.ts index 98f8dabd75..669ee57766 100644 --- a/src/lib/translation/context.ts +++ b/src/lib/translation/context.ts @@ -1,16 +1,19 @@ import {createContext} from 'react' -import {type Options, type TranslationState} from './types' +import {type TranslationState} from './types' export const Context = createContext<{ translationState: Record - translate: ( - key: string, - text: string, - targetLangCode: string, - sourceLangCode?: string, - options?: Options, - ) => Promise + translate: (parameters: { + key: string + text: string + targetLangCode: string + sourceLangCode?: string + /** + * Whether to force the use of Google Translate. Default is false. + */ + forceGoogleTranslate?: boolean + }) => Promise clearTranslation: (key: string) => void acquireTranslation: (key: string) => () => void } | null>(null) diff --git a/src/lib/translation/index.tsx b/src/lib/translation/index.tsx index ec306f606e..9ebee4d49e 100644 --- a/src/lib/translation/index.tsx +++ b/src/lib/translation/index.tsx @@ -6,10 +6,9 @@ import {useFocusEffect} from '@react-navigation/native' import {useGoogleTranslate} from '#/lib/hooks/useGoogleTranslate' import {logger} from '#/logger' -import {useLanguagePrefs} from '#/state/preferences' import {useAnalytics} from '#/analytics' import {Context} from './context' -import {type Options, type TranslationState} from './types' +import {type TranslationState} from './types' /** * Attempts on-device translation via @bsky.app/expo-translate-text. @@ -111,7 +110,6 @@ export function Provider({children}: React.PropsWithChildren) { >({}) const [refCounts, setRefCounts] = useState>({}) const ax = useAnalytics() - const {primaryLanguage} = useLanguagePrefs() const googleTranslate = useGoogleTranslate() useEffect(() => { @@ -163,14 +161,20 @@ export function Provider({children}: React.PropsWithChildren) { }, []) const translate = useCallback( - async ( - key: string, - text: string, - targetLangCode: string = primaryLanguage, - sourceLangCode?: string, - options?: Options, - ) => { - if (options?.googleTranslate) { + async ({ + key, + text, + targetLangCode, + sourceLangCode, + ...options + }: { + key: string + text: string + targetLangCode: string + sourceLangCode?: string + forceGoogleTranslate?: boolean + }) => { + if (options?.forceGoogleTranslate) { ax.metric('translate:result', { method: 'google-translate', os: Platform.OS, @@ -225,7 +229,7 @@ export function Provider({children}: React.PropsWithChildren) { await googleTranslate(text, targetLangCode, sourceLangCode) } }, - [ax, googleTranslate, primaryLanguage], + [ax, googleTranslate], ) const ctx = useMemo( diff --git a/src/lib/translation/index.web.tsx b/src/lib/translation/index.web.tsx index 5cc38805db..3ed4811392 100644 --- a/src/lib/translation/index.web.tsx +++ b/src/lib/translation/index.web.tsx @@ -1,10 +1,9 @@ import {useCallback, useContext, useMemo} from 'react' import {useGoogleTranslate} from '#/lib/hooks/useGoogleTranslate' -import {useLanguagePrefs} from '#/state/preferences' import {useAnalytics} from '#/analytics' import {Context} from './context' -import {type Options, type TranslationState} from './types' +import {type TranslationState} from './types' const translationState: Record = {} const acquireTranslation = (_key: string) => { @@ -29,17 +28,19 @@ export function useTranslate() { export function Provider({children}: React.PropsWithChildren) { const ax = useAnalytics() - const {primaryLanguage} = useLanguagePrefs() const googleTranslate = useGoogleTranslate() const translate = useCallback( - async ( - _key: string, - text: string, - targetLangCode: string = primaryLanguage, - sourceLangCode?: string, - _options?: Options, - ) => { + async ({ + text, + targetLangCode, + sourceLangCode, + }: { + key: string + text: string + targetLangCode: string + sourceLangCode?: string + }) => { ax.metric('translate:result', { method: 'google-translate', os: 'web', @@ -48,7 +49,7 @@ export function Provider({children}: React.PropsWithChildren) { }) await googleTranslate(text, targetLangCode, sourceLangCode) }, - [ax, googleTranslate, primaryLanguage], + [ax, googleTranslate], ) const ctx = useMemo( diff --git a/src/lib/translation/types.ts b/src/lib/translation/types.ts index f43b881605..bd898fa5b6 100644 --- a/src/lib/translation/types.ts +++ b/src/lib/translation/types.ts @@ -9,10 +9,3 @@ export type TranslationState = sourceLanguage: TranslationTaskResult['sourceLanguage'] targetLanguage: TranslationTaskResult['targetLanguage'] } - -export type Options = { - /** - * Whether to force the use of Google Translate. Default is false. - */ - googleTranslate?: boolean -} diff --git a/src/screens/PostThread/components/ThreadItemAnchor.tsx b/src/screens/PostThread/components/ThreadItemAnchor.tsx index 7211f82c23..ab8ee250d5 100644 --- a/src/screens/PostThread/components/ThreadItemAnchor.tsx +++ b/src/screens/PostThread/components/ThreadItemAnchor.tsx @@ -312,8 +312,6 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({ } } - const translationKey = post.uri - return ( <> @@ -409,10 +407,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({ shouldProxyLinks={true} /> ) : undefined} - + {post.embed && ( diff --git a/src/screens/PostThread/components/ThreadItemPost.tsx b/src/screens/PostThread/components/ThreadItemPost.tsx index c4ff88def3..d0de13a1d8 100644 --- a/src/screens/PostThread/components/ThreadItemPost.tsx +++ b/src/screens/PostThread/components/ThreadItemPost.tsx @@ -336,6 +336,7 @@ const ThreadItemPostInner = memo(function ThreadItemPostInner({ onPressReply={onPressReply} logContext="PostThreadItem" threadgateRecord={threadgateRecord} + forceGoogleTranslate={true} /> diff --git a/src/screens/PostThread/components/ThreadItemTreePost.tsx b/src/screens/PostThread/components/ThreadItemTreePost.tsx index a12e32b189..6dcfd3a9e4 100644 --- a/src/screens/PostThread/components/ThreadItemTreePost.tsx +++ b/src/screens/PostThread/components/ThreadItemTreePost.tsx @@ -377,6 +377,7 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({ onPressReply={onPressReply} logContext="PostThreadItem" threadgateRecord={threadgateRecord} + forceGoogleTranslate={true} /> diff --git a/src/screens/VideoFeed/index.tsx b/src/screens/VideoFeed/index.tsx index f4010f2caf..073553c098 100644 --- a/src/screens/VideoFeed/index.tsx +++ b/src/screens/VideoFeed/index.tsx @@ -33,9 +33,7 @@ import { type ModerationDecision, RichText as RichTextAPI, } from '@atproto/api' -import {msg} from '@lingui/core/macro' -import {useLingui} from '@lingui/react' -import {Trans} from '@lingui/react/macro' +import {Trans, useLingui} from '@lingui/react/macro' import { type RouteProp, useFocusEffect, @@ -451,7 +449,7 @@ function Feed() { } onEndReached={() => { if (hasNextPage && !isFetchingNextPage) { - fetchNextPage() + void fetchNextPage() } }} showsVerticalScrollIndicator={false} @@ -515,6 +513,7 @@ let VideoItem = ({ } } }, [ + ax, active, post.uri, post.author.did, @@ -621,7 +620,7 @@ function ModerationOverlay({ embed: AppBskyEmbedVideo.View onPressShow: () => void }) { - const {_} = useLingui() + const {t: l} = useLingui() const hider = Hider.useHider() const {bottom} = useSafeAreaInsets() @@ -648,7 +647,7 @@ function ModerationOverlay({ Hidden by your moderation settings.