Fix language detection taking mentions and URLs into account (#33700)

This commit is contained in:
Claire 2025-01-23 11:25:14 +01:00 committed by GitHub
parent 8eee7ae4c3
commit 3178acc5cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,6 +8,7 @@ import { debounce } from 'lodash';
import { changeComposeLanguage } from 'mastodon/actions/compose'; import { changeComposeLanguage } from 'mastodon/actions/compose';
import LanguageDropdown from '../components/language_dropdown'; import LanguageDropdown from '../components/language_dropdown';
import { urlRegex } from '../util/url_regex';
const getFrequentlyUsedLanguages = createSelector([ const getFrequentlyUsedLanguages = createSelector([
state => state.getIn(['settings', 'frequentlyUsedLanguages'], ImmutableMap()), state => state.getIn(['settings', 'frequentlyUsedLanguages'], ImmutableMap()),
@ -71,7 +72,16 @@ const ISO_639_MAP = {
vie: 'vi', // Vietnamese 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([ const detectedLanguage = createSelector([
state => state.getIn(['compose', 'text']), state => state.getIn(['compose', 'text']),