diff --git a/package-lock.json b/package-lock.json index a1f84c05..2fc71ac7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "react-router-dom": "6.6.2", "string-length": "6.0.0", "swiped-events": "~1.2.0", + "tinyld": "~1.3.4", "toastify-js": "~1.12.0", "uid": "~2.0.2", "use-debounce": "~10.0.0", @@ -8009,6 +8010,21 @@ "node": ">=10" } }, + "node_modules/tinyld": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/tinyld/-/tinyld-1.3.4.tgz", + "integrity": "sha512-u26CNoaInA4XpDU+8s/6Cq8xHc2T5M4fXB3ICfXPokUQoLzmPgSZU02TAkFwFMJCWTjk53gtkS8pETTreZwCqw==", + "bin": { + "tinyld": "bin/tinyld.js", + "tinyld-heavy": "bin/tinyld-heavy.js", + "tinyld-light": "bin/tinyld-light.js" + }, + "engines": { + "node": ">= 12.10.0", + "npm": ">= 6.12.0", + "yarn": ">= 1.20.0" + } + }, "node_modules/to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", diff --git a/package.json b/package.json index 6557142f..477501aa 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "react-router-dom": "6.6.2", "string-length": "6.0.0", "swiped-events": "~1.2.0", + "tinyld": "~1.3.4", "toastify-js": "~1.12.0", "uid": "~2.0.2", "use-debounce": "~10.0.0", diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 3972e547..7e0eacc2 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -15,6 +15,7 @@ import { } from 'preact/hooks'; import { useHotkeys } from 'react-hotkeys-hook'; import stringLength from 'string-length'; +import { detectAll } from 'tinyld/light'; import { uid } from 'uid/single'; import { useDebouncedCallback, useThrottledCallback } from 'use-debounce'; import { useSnapshot } from 'valtio'; @@ -635,6 +636,7 @@ function Compose({ const [showEmoji2Picker, setShowEmoji2Picker] = useState(false); const [showGIFPicker, setShowGIFPicker] = useState(false); + const [autoDetectedLanguages, setAutoDetectedLanguages] = useState(null); const [topSupportedLanguages, restSupportedLanguages] = useMemo(() => { const topLanguages = []; const restLanguages = []; @@ -645,7 +647,8 @@ function Compose({ code === language || code === prevLanguage.current || code === DEFAULT_LANG || - contentTranslationHideLanguages.includes(code) + contentTranslationHideLanguages.includes(code) || + (autoDetectedLanguages?.length && autoDetectedLanguages.includes(code)) ) { topLanguages.push(l); } else { @@ -661,7 +664,7 @@ function Compose({ commonA.localeCompare(commonB), ); return [topLanguages, restLanguages]; - }, [language]); + }, [language, autoDetectedLanguages]); const replyToStatusMonthsAgo = useMemo( () => @@ -1172,6 +1175,11 @@ function Compose({ setShowMentionPicker({ defaultSearchTerm: action?.defaultSearchTerm || null, }); + } else if ( + action?.name === 'auto-detect-language' && + action?.languages + ) { + setAutoDetectedLanguages(action.languages); } }} /> @@ -1354,7 +1362,11 @@ function Compose({ )}