···11+# Translation
22+33+A hook for translating text on-device for inline display.
44+55+## Translating text
66+77+```tsx
88+const langPrefs = useLanguagePrefs()
99+const {translate} = useTranslate({key: post.uri})
1010+1111+// ...
1212+1313+void translate({
1414+ text: record.text,
1515+ targetLangCode: langPrefs.primaryLanguage,
1616+})
1717+```
1818+1919+## Clearing/hiding a translation
2020+2121+```tsx
2222+const {clearTranslation} = useTranslate({key: post.uri})
2323+2424+// ...
2525+2626+clearTranslation()
2727+```
2828+2929+## Rendering a translation
3030+3131+```tsx
3232+const {translationState} = useTranslate({key: post.uri})
3333+3434+// ...
3535+3636+switch (translationState.status) {
3737+ case 'idle':
3838+ // Default state; render a link that calls `translate`.
3939+ break;
4040+ case 'loading':
4141+ // On-device translation is in progress; render a loading spinner.
4242+ break;
4343+ case 'success':
4444+ // Translation complete; render `translationState.translatedText` and a link
4545+ // that calls `clearTranslation`.
4646+ break;
4747+ case 'error':
4848+ // On-device translation failed; render `translationState.message` and a
4949+ // link to `translate` from `useGoogleTranslate` as a fallback.
5050+ break;
5151+}
5252+```
5353+5454+## Notes
5555+5656+* Android only supports two-letter language codes.
5757+ * For example, this means it doesn’t differentiate between `pt-BR` and `pt-PT`.
5858+* Android and iOS only support a subset of the language options we offer (iOS supports fewer than Android).
5959+* Individual language packs must be downloaded on iOS.