Bluesky app fork with some witchin' additions 💫 witchsky.app
bluesky fork client

Add README.md for lib/translation (#10005)

authored by

DS Boyce and committed by
GitHub
fe8e8ce7 8b8acb7b

+59
+59
src/lib/translation/README.md
··· 1 + # Translation 2 + 3 + A hook for translating text on-device for inline display. 4 + 5 + ## Translating text 6 + 7 + ```tsx 8 + const langPrefs = useLanguagePrefs() 9 + const {translate} = useTranslate({key: post.uri}) 10 + 11 + // ... 12 + 13 + void translate({ 14 + text: record.text, 15 + targetLangCode: langPrefs.primaryLanguage, 16 + }) 17 + ``` 18 + 19 + ## Clearing/hiding a translation 20 + 21 + ```tsx 22 + const {clearTranslation} = useTranslate({key: post.uri}) 23 + 24 + // ... 25 + 26 + clearTranslation() 27 + ``` 28 + 29 + ## Rendering a translation 30 + 31 + ```tsx 32 + const {translationState} = useTranslate({key: post.uri}) 33 + 34 + // ... 35 + 36 + switch (translationState.status) { 37 + case 'idle': 38 + // Default state; render a link that calls `translate`. 39 + break; 40 + case 'loading': 41 + // On-device translation is in progress; render a loading spinner. 42 + break; 43 + case 'success': 44 + // Translation complete; render `translationState.translatedText` and a link 45 + // that calls `clearTranslation`. 46 + break; 47 + case 'error': 48 + // On-device translation failed; render `translationState.message` and a 49 + // link to `translate` from `useGoogleTranslate` as a fallback. 50 + break; 51 + } 52 + ``` 53 + 54 + ## Notes 55 + 56 + * Android only supports two-letter language codes. 57 + * For example, this means it doesn’t differentiate between `pt-BR` and `pt-PT`. 58 + * Android and iOS only support a subset of the language options we offer (iOS supports fewer than Android). 59 + * Individual language packs must be downloaded on iOS.