From 3178acc5cb8415a72b646dbe77be05255d3966f3 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 23 Jan 2025 11:25:14 +0100 Subject: [PATCH] Fix language detection taking mentions and URLs into account (#33700) --- .../containers/language_dropdown_container.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/features/compose/containers/language_dropdown_container.js b/app/javascript/mastodon/features/compose/containers/language_dropdown_container.js index f914aa2b78..64d6516a18 100644 --- a/app/javascript/mastodon/features/compose/containers/language_dropdown_container.js +++ b/app/javascript/mastodon/features/compose/containers/language_dropdown_container.js @@ -8,6 +8,7 @@ import { debounce } from 'lodash'; import { changeComposeLanguage } from 'mastodon/actions/compose'; import LanguageDropdown from '../components/language_dropdown'; +import { urlRegex } from '../util/url_regex'; const getFrequentlyUsedLanguages = createSelector([ state => state.getIn(['settings', 'frequentlyUsedLanguages'], ImmutableMap()), @@ -71,7 +72,16 @@ const ISO_639_MAP = { vie: 'vi', // Vietnamese }; -const debouncedLande = debounce((text) => lande(text), 500, { trailing: true }); +const debouncedLande = debounce((text) => { + text = text + .replace(urlRegex, '') + .replace(/(^|[^/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig, ''); + + if (text.length <= 20) + return undefined; + + return lande(text); +}, 500, { trailing: true }); const detectedLanguage = createSelector([ state => state.getIn(['compose', 'text']),