This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
expo-translate-text is a published npm package — an Expo native module that exposes platform-native translation APIs to React Native. It uses Apple's Translation framework on iOS and Google ML Kit on Android. There is no server-side component.
yarn # install all dependencies
yarn build # compile TypeScript → build/
yarn lint # ESLint + Prettier check
yarn lint --fix # auto-fix formatting
yarn typecheck # tsc type check
yarn test # Jest unit tests
# Example app
yarn example:start # start Metro bundler
yarn example:ios # run on iOS (physical device only — Translation not supported on simulator)
yarn example:android # run on Android emulator/device
# Open native projects
yarn open:ios # open example/ios in Xcode
yarn open:android # open example/android in Android StudioNative code changes require a full rebuild of the example app. TypeScript/JS changes hot-reload without rebuilding.
Publishing: yarn release (release-it — bumps semver, creates git tag, publishes to npm).
ExpoTranslateText.types.ts— shared TypeScript interfaces for requests and responsesExpoTranslateTextModule.ts— loads the native module viarequireNativeModule('ExpoTranslateText')and exportsTranslationErrorindex.ts— public API; wraps the raw native calls inonTranslateTaskandonTranslateSheet, normalises errors intoTranslationError
The build/ directory is the compiled output (committed) — this is what gets published to npm.
Built against Apple's Translation framework (gated on #if canImport(Translation)):
ExpoTranslateTextModule.swift— Expo module definition; exposestranslateTaskandtranslateSheetasync functions. Manages a hiddenUIHostingController(1×1px, invisible) that hosts the SwiftUI views needed to drive the Translation API.Props.swift—ObservableObjectstate bridges between the module and the SwiftUI views (Propsfor task mode,SheetPropsfor sheet mode).TranslationViews.swift— SwiftUI views:IOSTranslateTasksattaches.translationTaskmodifier;IOSTranslateSheetattaches.translationPresentationmodifier. These views are the actual entry points into the Apple Translation framework.Exceptions.swift— typedExceptionsubclasses used by the module (surfaces string error codes to JS matching Android's convention).TranslationHelpers.swift—parseTexts()flattens string/array/dict input into[String];makeConfiguration()buildsTranslationSession.Configuration.
Key iOS design pattern: Apple's Translation API requires SwiftUI view modifiers (.translationTask, .translationPresentation). The module works around this by programmatically attaching a hidden UIHostingController to the root view controller, using ObservableObject props as a data bridge, and tearing it down after translation completes.
Version gates: translateTask requires iOS 18.0+; translateSheet requires iOS 17.4+.
Uses Google ML Kit's on-device translation (com.google.mlkit:translate):
ExpoTranslateTextModule.kt— single file; exposes onlytranslateTask(no sheet support on Android). Handles: input flattening (extractItems), optional language identification via ML Kit'sLanguageIdentification, model download with configurableDownloadConditions(WiFi, charging), parallel translation withAtomicBoolean/AtomicIntegerfor safe promise settlement, and output reconstruction (reconstructOutput).
Key Android design pattern: All three input shapes (string, array, dict) are flattened into a list of TranslationItem with positional metadata, translated in parallel, then reconstructed back to the original shape. When sourceLangCode is omitted, each item is language-detected individually before translation.
Both platforms handle three input shapes identically:
string→stringstring[]→string[]{ [key: string]: string | string[] }→ same shape with values translated
A minimal Expo app configured with autolinking.nativeModulesDir: ".." to consume the local module source directly. Used to manually test native changes.
Follows Conventional Commits: fix:, feat:, refactor:, docs:, test:, chore:. Pre-commit hooks enforce this format and run linter + tests.