Use on-device translation on mobile when available (#9930)

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
DS Boyce
2026-02-27 16:59:19 -08:00
committed by GitHub
parent 7c9f05a2af
commit 9bbcb472ef
17 changed files with 4620 additions and 608 deletions
+12 -4
View File
@@ -1,19 +1,27 @@
import {useCallback} from 'react'
import * as IntentLauncher from 'expo-intent-launcher'
import {useOpenLink} from '#/lib/hooks/useOpenLink'
import {getTranslatorLink} from '#/locale/helpers'
import {IS_ANDROID} from '#/env'
import {useOpenLink} from './useOpenLink'
/**
* Will always link out to Google Translate. If inline translation is desired,
* use `useTranslateOnDevice`
*/
export function useTranslate() {
const openLink = useOpenLink()
return useCallback(
async (text: string, language: string) => {
const translateUrl = getTranslatorLink(text, language)
async (text: string, targetLangCode: string, sourceLanguage?: string) => {
const translateUrl = getTranslatorLink(
text,
targetLangCode,
sourceLanguage,
)
if (IS_ANDROID) {
try {
// use getApplicationIconAsync to determine if the translate app is installed
// use `getApplicationIconAsync` to determine if the translate app is installed
if (
!(await IntentLauncher.getApplicationIconAsync(
'com.google.android.apps.translate',