From f11b94505d83e4f25f561596c9f0f490994e5f50 Mon Sep 17 00:00:00 2001 From: Sedat Kapanoglu Date: Tue, 14 Jan 2025 13:00:36 -0800 Subject: [PATCH] add more comments --- .../com/composer/select-language/SuggestedLanguage.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/view/com/composer/select-language/SuggestedLanguage.tsx b/src/view/com/composer/select-language/SuggestedLanguage.tsx index 32513aeca3..4f32c48cb8 100644 --- a/src/view/com/composer/select-language/SuggestedLanguage.tsx +++ b/src/view/com/composer/select-language/SuggestedLanguage.tsx @@ -35,8 +35,16 @@ export function SuggestedLanguage({text}: {text: string}) { useEffect(() => { let textTrimmed = text.trim() - // remove the last word before guessing to prevent a half-written word + // Remove the last word before guessing to prevent a half-written word // from botching the confidence of language detection. + // There are two gotchas with this approach: + // First, it might increase the practical minimum length for the language + // detection because removing the last word would eat away from the + // 40 character min limit. I think it's worth it though. + // Second, this will also discard the last word that has been typed fully + // which might affect the outcome. One might consider detecting punctuation + // at the end of the last word to include it in the language detection, + // but it's quite hard to do that for all languages correctly. const lastSpace = textTrimmed.lastIndexOf(' ') if (lastSpace > 0) { textTrimmed = textTrimmed.slice(0, lastSpace)