Skip to content

Commit

Permalink
improve language detection accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
ssg committed Jan 14, 2025
1 parent 479a4a9 commit b3f5668
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/view/com/composer/select-language/SuggestedLanguage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ export function SuggestedLanguage({text}: {text: string}) {
const {_} = useLingui()

useEffect(() => {
const textTrimmed = text.trim()
let textTrimmed = text.trim()

// remove the last word before guessing to prevent a half-written word
// from botching the confidence of language detection.
const lastSpace = textTrimmed.lastIndexOf(' ')
if (lastSpace > 0) {
textTrimmed = textTrimmed.slice(0, lastSpace)
}

// Don't run the language model on small posts, the results are likely
// to be inaccurate anyway.
Expand Down

0 comments on commit b3f5668

Please sign in to comment.