Replace lande with native language detection (#9974)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: DS Boyce <260543580+ds-boyce@users.noreply.github.com>
Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
Samuel Newman
2026-04-22 18:26:14 +03:00
committed by GitHub
parent 5d40532aa9
commit 1c38665d4c
10 changed files with 706 additions and 141 deletions
+19
View File
@@ -268,6 +268,20 @@ export const ComposePost = ({
setReplyToLanguages([])
}
/**
* Timestamp (ms) of the last honored nudge from language detection.
* Used to rate-limit the pulse animation: we ignore back-to-back
* nudges that arrive within NUDGE_COOLDOWN_MS. Consumers key an effect
* on this value — it only changes when we actually want to re-pulse.
*/
const [languageNudgeAt, setLanguageNudgeAt] = useState(0)
const onLanguageNudge = () => {
const now = Date.now()
// ignore back-to-back nudges within 10s; only update state (and
// therefore re-pulse) once the cooldown has elapsed
setLanguageNudgeAt(prev => (now - prev > 10_000 ? now : prev))
}
const [composerState, composerDispatch] = useReducer(
composerReducer,
{
@@ -1146,6 +1160,7 @@ export const ComposePost = ({
replyToLanguages={replyToLanguages}
currentLanguages={currentLanguages}
onAcceptSuggestedLanguage={setAcceptedLanguageSuggestion}
onNudge={onLanguageNudge}
/>
<ComposerPills
isReply={!!replyTo}
@@ -1169,6 +1184,7 @@ export const ComposePost = ({
}}
currentLanguages={currentLanguages}
onSelectLanguage={onSelectLanguage}
languageNudgeAt={languageNudgeAt}
openGallery={openGallery}
textInputRef={textInputRef}
/>
@@ -1873,6 +1889,7 @@ function ComposerFooter({
onAddPost,
currentLanguages,
onSelectLanguage,
languageNudgeAt,
openGallery,
textInputRef,
}: {
@@ -1884,6 +1901,7 @@ function ComposerFooter({
onAddPost: () => void
currentLanguages: string[]
onSelectLanguage?: (language: string) => void
languageNudgeAt: number
openGallery?: boolean
textInputRef: React.RefObject<TextInputRef | null>
}) {
@@ -2049,6 +2067,7 @@ function ComposerFooter({
<PostLanguageSelect
currentLanguages={currentLanguages}
onSelectLanguage={onSelectLanguage}
nudgeAt={languageNudgeAt}
/>
<CharProgress
count={post.shortenedGraphemeLength}