Update option name to forceGoogleTranslate
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -106,7 +106,7 @@ let PostMenuItems = ({
|
||||
threadgateRecord,
|
||||
onShowLess,
|
||||
logContext,
|
||||
googleTranslate,
|
||||
forceGoogleTranslate,
|
||||
}: {
|
||||
testID: string
|
||||
post: Shadow<AppBskyFeedDefs.PostView>
|
||||
@@ -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<AppBskyFeedPost.Record>(
|
||||
|
||||
@@ -29,7 +29,7 @@ let PostMenuButton = ({
|
||||
onShowLess,
|
||||
hitSlop,
|
||||
logContext,
|
||||
googleTranslate,
|
||||
forceGoogleTranslate,
|
||||
}: {
|
||||
testID: string
|
||||
post: Shadow<AppBskyFeedDefs.PostView>
|
||||
@@ -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}
|
||||
/>
|
||||
)}
|
||||
</Menu.Root>
|
||||
|
||||
@@ -55,7 +55,7 @@ let PostControls = ({
|
||||
onShowLess,
|
||||
viaRepost,
|
||||
variant,
|
||||
googleTranslate = true,
|
||||
forceGoogleTranslate = false,
|
||||
}: {
|
||||
big?: boolean
|
||||
post: Shadow<AppBskyFeedDefs.PostView>
|
||||
@@ -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 = ({
|
||||
<RepostButton
|
||||
isReposted={!!post.viewer?.repost}
|
||||
repostCount={(post.repostCount ?? 0) + (post.quoteCount ?? 0)}
|
||||
onRepost={onRepost}
|
||||
onRepost={() => 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}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -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<string, TranslationState>
|
||||
translate: (
|
||||
key: string,
|
||||
text: string,
|
||||
targetLangCode: string,
|
||||
sourceLangCode?: string,
|
||||
options?: Options,
|
||||
) => Promise<void>
|
||||
translate: (parameters: {
|
||||
key: string
|
||||
text: string
|
||||
targetLangCode: string
|
||||
sourceLangCode?: string
|
||||
/**
|
||||
* Whether to force the use of Google Translate. Default is false.
|
||||
*/
|
||||
forceGoogleTranslate?: boolean
|
||||
}) => Promise<void>
|
||||
clearTranslation: (key: string) => void
|
||||
acquireTranslation: (key: string) => () => void
|
||||
} | null>(null)
|
||||
|
||||
@@ -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<unknown>) {
|
||||
>({})
|
||||
const [refCounts, setRefCounts] = useState<Record<string, number>>({})
|
||||
const ax = useAnalytics()
|
||||
const {primaryLanguage} = useLanguagePrefs()
|
||||
const googleTranslate = useGoogleTranslate()
|
||||
|
||||
useEffect(() => {
|
||||
@@ -163,14 +161,20 @@ export function Provider({children}: React.PropsWithChildren<unknown>) {
|
||||
}, [])
|
||||
|
||||
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<unknown>) {
|
||||
await googleTranslate(text, targetLangCode, sourceLangCode)
|
||||
}
|
||||
},
|
||||
[ax, googleTranslate, primaryLanguage],
|
||||
[ax, googleTranslate],
|
||||
)
|
||||
|
||||
const ctx = useMemo(
|
||||
|
||||
@@ -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<string, TranslationState> = {}
|
||||
const acquireTranslation = (_key: string) => {
|
||||
@@ -29,17 +28,19 @@ export function useTranslate() {
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<unknown>) {
|
||||
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<unknown>) {
|
||||
})
|
||||
await googleTranslate(text, targetLangCode, sourceLangCode)
|
||||
},
|
||||
[ax, googleTranslate, primaryLanguage],
|
||||
[ax, googleTranslate],
|
||||
)
|
||||
|
||||
const ctx = useMemo(
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -312,8 +312,6 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
||||
}
|
||||
}
|
||||
|
||||
const translationKey = post.uri
|
||||
|
||||
return (
|
||||
<>
|
||||
<ThreadItemAnchorParentReplyLine isRoot={isRoot} />
|
||||
@@ -409,10 +407,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
||||
shouldProxyLinks={true}
|
||||
/>
|
||||
) : undefined}
|
||||
<TranslatedPost
|
||||
translationKey={translationKey}
|
||||
postText={record.text}
|
||||
/>
|
||||
<TranslatedPost translationKey={post.uri} postText={record.text} />
|
||||
{post.embed && (
|
||||
<View style={[a.py_xs]}>
|
||||
<Embed
|
||||
@@ -538,7 +533,7 @@ const ThreadItemAnchorInner = memo(function ThreadItemAnchorInner({
|
||||
feedContext={postSource?.post?.feedContext}
|
||||
reqId={postSource?.post?.reqId}
|
||||
viaRepost={viaRepost}
|
||||
googleTranslate={false}
|
||||
forceGoogleTranslate={true}
|
||||
/>
|
||||
</FeedFeedbackProvider>
|
||||
</View>
|
||||
|
||||
@@ -336,6 +336,7 @@ const ThreadItemPostInner = memo(function ThreadItemPostInner({
|
||||
onPressReply={onPressReply}
|
||||
logContext="PostThreadItem"
|
||||
threadgateRecord={threadgateRecord}
|
||||
forceGoogleTranslate={true}
|
||||
/>
|
||||
<DebugFieldDisplay subject={post} />
|
||||
</View>
|
||||
|
||||
@@ -377,6 +377,7 @@ const ThreadItemTreePostInner = memo(function ThreadItemTreePostInner({
|
||||
onPressReply={onPressReply}
|
||||
logContext="PostThreadItem"
|
||||
threadgateRecord={threadgateRecord}
|
||||
forceGoogleTranslate={true}
|
||||
/>
|
||||
<DebugFieldDisplay subject={post} />
|
||||
</View>
|
||||
|
||||
@@ -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({
|
||||
<Trans>Hidden by your moderation settings.</Trans>
|
||||
</Text>
|
||||
<Button
|
||||
label={_(msg`Show anyway`)}
|
||||
label={l`Show anyway`}
|
||||
size="small"
|
||||
variant="solid"
|
||||
color="secondary_inverted"
|
||||
@@ -676,7 +675,7 @@ function ModerationOverlay({
|
||||
<Divider style={{borderColor: 'white'}} />
|
||||
<View>
|
||||
<Button
|
||||
label={_(msg`View details`)}
|
||||
label={l`View details`}
|
||||
onPress={() => {
|
||||
hider.showInfoDialog()
|
||||
}}
|
||||
@@ -724,7 +723,7 @@ function Overlay({
|
||||
feedContext: string | undefined
|
||||
reqId: string | undefined
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const {t: l} = useLingui()
|
||||
const t = useTheme()
|
||||
const {openComposer} = useOpenComposer()
|
||||
const {currentAccount} = useSession()
|
||||
@@ -811,11 +810,9 @@ function Overlay({
|
||||
<Animated.View style={[a.px_md, animatedStyle]}>
|
||||
<View style={[a.w_full, a.flex_row, a.align_center, a.gap_md]}>
|
||||
<Link
|
||||
label={_(
|
||||
msg`View ${sanitizeDisplayName(
|
||||
post.author.displayName || post.author.handle,
|
||||
)}'s profile`,
|
||||
)}
|
||||
label={l`View ${sanitizeDisplayName(
|
||||
post.author.displayName || post.author.handle,
|
||||
)}'s profile`}
|
||||
to={{
|
||||
screen: 'Profile',
|
||||
params: {name: post.author.did},
|
||||
@@ -848,13 +845,11 @@ function Overlay({
|
||||
<Button
|
||||
label={
|
||||
profile.viewer?.following
|
||||
? _(msg`Following ${handle}`)
|
||||
: _(msg`Follow ${handle}`)
|
||||
? l`Following ${handle}`
|
||||
: l`Follow ${handle}`
|
||||
}
|
||||
accessibilityHint={
|
||||
profile.viewer?.following
|
||||
? _(msg`Unfollows the user`)
|
||||
: ''
|
||||
profile.viewer?.following ? l`Unfollows the user` : ''
|
||||
}
|
||||
size="small"
|
||||
variant="solid"
|
||||
@@ -862,8 +857,8 @@ function Overlay({
|
||||
style={[a.mb_xs]}
|
||||
onPress={() =>
|
||||
profile.viewer?.following
|
||||
? queueUnfollow()
|
||||
: queueFollow()
|
||||
? void queueUnfollow()
|
||||
: void queueFollow()
|
||||
}>
|
||||
{!!profile.viewer?.following && (
|
||||
<ButtonIcon icon={CheckIcon} />
|
||||
@@ -892,6 +887,7 @@ function Overlay({
|
||||
record={record}
|
||||
feedContext={feedContext}
|
||||
logContext="FeedItem"
|
||||
forceGoogleTranslate={true}
|
||||
onPressReply={() =>
|
||||
navigation.navigate('PostThread', {
|
||||
name: post.author.did,
|
||||
@@ -947,7 +943,7 @@ function ExpandableRichTextView({
|
||||
const [hasBeenExpanded, setHasBeenExpanded] = useState(false)
|
||||
const [constrained, setConstrained] = useState(false)
|
||||
const [contentHeight, setContentHeight] = useState(0)
|
||||
const {_} = useLingui()
|
||||
const {t: l} = useLingui()
|
||||
const {screenReaderEnabled} = useA11y()
|
||||
|
||||
if (expanded && !hasBeenExpanded) {
|
||||
@@ -988,8 +984,8 @@ function ExpandableRichTextView({
|
||||
/>
|
||||
{constrained && !screenReaderEnabled && (
|
||||
<Pressable
|
||||
accessibilityHint={_(msg`Expands or collapses post text`)}
|
||||
accessibilityLabel={expanded ? _(msg`Read less`) : _(msg`Read more`)}
|
||||
accessibilityHint={l`Expands or collapses post text`}
|
||||
accessibilityLabel={expanded ? l`Read less` : l`Read more`}
|
||||
hitSlop={HITSLOP_20}
|
||||
onPress={() => setExpanded(prev => !prev)}
|
||||
style={[a.absolute, a.inset_0]}
|
||||
@@ -1049,7 +1045,7 @@ function PlayPauseTapArea({
|
||||
feedContext: string | undefined
|
||||
reqId: string | undefined
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const {t: l} = useLingui()
|
||||
const doubleTapRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
const playHaptic = useHaptics()
|
||||
// TODO: implement viaRepost -sfn
|
||||
@@ -1092,7 +1088,7 @@ function PlayPauseTapArea({
|
||||
clearTimeout(doubleTapRef.current)
|
||||
doubleTapRef.current = null
|
||||
playHaptic('Light')
|
||||
queueLike()
|
||||
void queueLike()
|
||||
sendInteraction({
|
||||
item: post.uri,
|
||||
event: 'app.bsky.feed.defs#interactionLike',
|
||||
@@ -1107,16 +1103,12 @@ function PlayPauseTapArea({
|
||||
return (
|
||||
<Button
|
||||
disabled={!player}
|
||||
aria-valuetext={
|
||||
isPlaying ? _(msg`Video is playing`) : _(msg`Video is paused`)
|
||||
}
|
||||
label={_(
|
||||
msg`Video from ${sanitizeHandle(
|
||||
post.author.handle,
|
||||
'@',
|
||||
)}. Tap to play or pause the video`,
|
||||
)}
|
||||
accessibilityHint={_(msg`Double tap to like`)}
|
||||
aria-valuetext={isPlaying ? l`Video is playing` : l`Video is paused`}
|
||||
label={l`Video from ${sanitizeHandle(
|
||||
post.author.handle,
|
||||
'@',
|
||||
)}. Tap to play or pause the video`}
|
||||
accessibilityHint={l`Double tap to like`}
|
||||
onPress={onPress}
|
||||
style={[a.absolute, a.inset_0, a.z_10]}>
|
||||
<View />
|
||||
@@ -1126,7 +1118,7 @@ function PlayPauseTapArea({
|
||||
|
||||
function EndMessage() {
|
||||
const navigation = useNavigation<NavigationProp>()
|
||||
const {_} = useLingui()
|
||||
const {t: l} = useLingui()
|
||||
const t = useTheme()
|
||||
return (
|
||||
<View
|
||||
@@ -1177,8 +1169,8 @@ function EndMessage() {
|
||||
variant="solid"
|
||||
color="secondary_inverted"
|
||||
size="small"
|
||||
label={_(msg`Go back`)}
|
||||
accessibilityHint={_(msg`Returns to previous page`)}>
|
||||
label={l`Go back`}
|
||||
accessibilityHint={l`Returns to previous page`}>
|
||||
<ButtonIcon icon={ArrowLeftIcon} />
|
||||
<ButtonText>
|
||||
<Trans>Go back</Trans>
|
||||
|
||||
@@ -154,8 +154,6 @@ function PostInner({
|
||||
|
||||
const [hover, setHover] = useState(false)
|
||||
|
||||
const translationKey = post.uri
|
||||
|
||||
return (
|
||||
<Link
|
||||
href={itemHref}
|
||||
@@ -220,7 +218,7 @@ function PostInner({
|
||||
/>
|
||||
)}
|
||||
<TranslatedPost
|
||||
translationKey={translationKey}
|
||||
translationKey={post.uri}
|
||||
postText={record.text}
|
||||
/>
|
||||
</View>
|
||||
@@ -239,7 +237,6 @@ function PostInner({
|
||||
richText={richText}
|
||||
onPressReply={onPressReply}
|
||||
logContext="Post"
|
||||
googleTranslate={false}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user