Skip to content

Commit

Permalink
[Glitch] Fix language detection taking mentions and URLs into account
Browse files Browse the repository at this point in the history
Port 3178acc to glitch-soc

Signed-off-by: Claire <[email protected]>
  • Loading branch information
ClearlyClaire committed Jan 23, 2025
1 parent 38905ae commit 45093e7
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { debounce } from 'lodash';
import { changeComposeLanguage } from 'flavours/glitch/actions/compose';

import LanguageDropdown from '../components/language_dropdown';
import { urlRegex } from '../util/url_regex';

const getFrequentlyUsedLanguages = createSelector([
state => state.getIn(['settings', 'frequentlyUsedLanguages'], ImmutableMap()),
Expand Down Expand Up @@ -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']),
Expand Down

0 comments on commit 45093e7

Please sign in to comment.