From bbc55eb0d7e78a6c5f0a716d95872cad66fb2456 Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Tue, 9 Sep 2025 18:33:23 +0300
Subject: clean up language before suggesting (#9006)

---
 src/view/com/composer/select-language/SuggestedLanguage.tsx | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

(limited to 'src/view/com/composer/select-language/SuggestedLanguage.tsx')

diff --git a/src/view/com/composer/select-language/SuggestedLanguage.tsx b/src/view/com/composer/select-language/SuggestedLanguage.tsx
index 48e2187b8..431787cea 100644
--- a/src/view/com/composer/select-language/SuggestedLanguage.tsx
+++ b/src/view/com/composer/select-language/SuggestedLanguage.tsx
@@ -1,5 +1,6 @@
 import {useEffect, useState} from 'react'
 import {View} from 'react-native'
+import {parseLanguage} from '@atproto/api'
 import {msg, Trans} from '@lingui/macro'
 import {useLingui} from '@lingui/react'
 import lande from 'lande'
@@ -21,11 +22,12 @@ const cancelIdle = globalThis.cancelIdleCallback || clearTimeout
 
 export function SuggestedLanguage({
   text,
-  replyToLanguage,
+  replyToLanguage: replyToLanguageProp,
 }: {
   text: string
   replyToLanguage?: string
 }) {
+  const replyToLanguage = cleanUpLanguage(replyToLanguageProp)
   const [suggestedLanguage, setSuggestedLanguage] = useState<
     string | undefined
   >(text.length === 0 ? replyToLanguage : undefined)
@@ -125,3 +127,11 @@ function guessLanguage(text: string): string | undefined {
   }
   return code3ToCode2Strict(lang)
 }
+
+function cleanUpLanguage(text: string | undefined): string | undefined {
+  if (!text) {
+    return undefined
+  }
+
+  return parseLanguage(text)?.language
+}
-- 
cgit 1.4.1

