clean up language before suggesting (#9006)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import {useEffect, useState} from 'react'
|
import {useEffect, useState} from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
|
import {parseLanguage} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import lande from 'lande'
|
import lande from 'lande'
|
||||||
@@ -21,11 +22,12 @@ const cancelIdle = globalThis.cancelIdleCallback || clearTimeout
|
|||||||
|
|
||||||
export function SuggestedLanguage({
|
export function SuggestedLanguage({
|
||||||
text,
|
text,
|
||||||
replyToLanguage,
|
replyToLanguage: replyToLanguageProp,
|
||||||
}: {
|
}: {
|
||||||
text: string
|
text: string
|
||||||
replyToLanguage?: string
|
replyToLanguage?: string
|
||||||
}) {
|
}) {
|
||||||
|
const replyToLanguage = cleanUpLanguage(replyToLanguageProp)
|
||||||
const [suggestedLanguage, setSuggestedLanguage] = useState<
|
const [suggestedLanguage, setSuggestedLanguage] = useState<
|
||||||
string | undefined
|
string | undefined
|
||||||
>(text.length === 0 ? replyToLanguage : undefined)
|
>(text.length === 0 ? replyToLanguage : undefined)
|
||||||
@@ -125,3 +127,11 @@ function guessLanguage(text: string): string | undefined {
|
|||||||
}
|
}
|
||||||
return code3ToCode2Strict(lang)
|
return code3ToCode2Strict(lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanUpLanguage(text: string | undefined): string | undefined {
|
||||||
|
if (!text) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseLanguage(text)?.language
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user