···2727 * The source language of the text. Will auto-detect if not provided.
2828 */
2929 sourceLangCode?: string
3030+ /**
3131+ * Whether we auto-detected the language or it was selected manually. Defaults to 'automatic'.
3232+ */
3333+ sourceSelection?: 'automatic' | 'manual'
3434+}
3535+3636+export type TranslationOptions = {
3737+ key: string
3838+ forceGoogleTranslate?: boolean
3939+ /**
4040+ * The language(s) of the post being translated. Used for analytics purposes
4141+ * to understand translation usage patterns better. Optional because it may
4242+ * not always be available (e.g. if the post text is empty or if the
4343+ * translation is triggered from a non-post
4444+ * context).
4545+ */
4646+ postLangCodes?: string[]
3047}
31483249export type TranslationFunction = (
3350 parameters: TranslationFunctionParams,
3451) => Promise<void>
5252+5353+export type ContextType = {
5454+ translationState: Record<string, TranslationState>
5555+ translate: (
5656+ parameters: TranslationFunctionParams & TranslationOptions,
5757+ ) => Promise<void>
5858+ clearTranslation: (key: string) => void
5959+ acquireTranslation: (key: string) => () => void
6060+}
+13-14
src/locale/helpers.ts
···6161 }
6262}
63636464+export function getPostLanguageTags(post: AppBskyFeedDefs.PostView) {
6565+ return AppBskyFeedPost.isRecord(post.record) &&
6666+ hasProp(post.record, 'langs') &&
6767+ Array.isArray(post.record.langs)
6868+ ? post.record.langs
6969+ : []
7070+}
7171+6472export function languageName(language: Language, appLang: string): string {
6573 // if Intl.DisplayNames is unavailable on the target, display the English name
6674 if (!Intl.DisplayNames) {
···8088export function getPostLanguage(
8189 post: AppBskyFeedDefs.PostView,
8290): string | undefined {
8383- let candidates: string[] = []
9191+ let candidates: string[] = getPostLanguageTags(post)
8492 let postText: string = ''
8593 if (hasProp(post.record, 'text') && typeof post.record.text === 'string') {
8694 postText = post.record.text
8795 }
88968989- if (
9090- AppBskyFeedPost.isRecord(post.record) &&
9191- hasProp(post.record, 'langs') &&
9292- Array.isArray(post.record.langs)
9393- ) {
9494- candidates = post.record.langs
9595- }
9696-9797 // if there's only one declared language, use that
9898- if (candidates?.length === 1) {
9898+ if (candidates.length === 1) {
9999 return candidates[0]
100100 }
101101···108108 let langsProbabilityMap = lande(postText)
109109110110 // filter down using declared languages
111111- if (candidates?.length) {
111111+ if (candidates.length) {
112112 langsProbabilityMap = langsProbabilityMap.filter(
113113- ([lang, _probability]: [string, number]) => {
114114- return candidates.includes(code3ToCode2(lang))
115115- },
113113+ ([lang, _probability]: [string, number]) =>
114114+ candidates.includes(code3ToCode2(lang)),
116115 )
117116 }
118117
+4-4
yarn.lock
···24032403 resolved "https://registry.yarnpkg.com/@bsky.app/expo-image-crop-tool/-/expo-image-crop-tool-0.5.0.tgz#4308fbde5c15e6be9122601797bc3d9549c95e31"
24042404 integrity sha512-gmhQr2HWTRFyPO00fn5OmtiEVtikXusHMrN5Zoq26pu1VZX3zVE+aoc668etTqrvsQcm2Qu8fo96k5F3Wu+6wg==
2405240524062406-"@bsky.app/expo-translate-text@^0.2.7":
24072407- version "0.2.7"
24082408- resolved "https://registry.yarnpkg.com/@bsky.app/expo-translate-text/-/expo-translate-text-0.2.7.tgz#e34811d0f0300f8808762e5676aa50790ca5d5e8"
24092409- integrity sha512-J9zctP9hLxX0eustTKk5CBnCkk6cEdlu1s7GzUnpT65qkCSNbYqbbUCpcU2Z2S2dN/1+w6L/iHb+vmCEbZMOaQ==
24062406+"@bsky.app/expo-translate-text@^0.2.9":
24072407+ version "0.2.9"
24082408+ resolved "https://registry.yarnpkg.com/@bsky.app/expo-translate-text/-/expo-translate-text-0.2.9.tgz#4ed4552cd50bca7d02d14e706e419bd728d4ab51"
24092409+ integrity sha512-VmqMhc/YavjgkGhxT/fB8mGSi+VZHJET1tsbpTg8peqKRXFSju2F294NsRxH/4aaMQFlt5oRfPCRnLm1H5o3lA==
2410241024112411"@bsky.app/react-native-mmkv@2.12.5":
24122412 version "2.12.5"