[Glitch] Fix language detection taking mentions and URLs into account
Port 3178acc5cb
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
pull/2953/head
parent
38905ae658
commit
45093e7abf
|
@ -8,6 +8,7 @@ import { debounce } from 'lodash';
|
||||||
import { changeComposeLanguage } from 'flavours/glitch/actions/compose';
|
import { changeComposeLanguage } from 'flavours/glitch/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']),
|
||||||
|
|
Loading…
Reference in New Issue