diff --git a/src/components/status.jsx b/src/components/status.jsx index aaa2f529..cd9cca67 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -125,6 +125,46 @@ function getPostText(status) { ); } +function isTranslateble(content) { + if (!content) return false; + content = content.trim(); + if (!content) return false; + const text = getHTMLText(content, { + preProcess: (dom) => { + // Remove .mention, pre, code, a:has(.invisible) + for (const a of dom.querySelectorAll( + '.mention, pre, code, a:has(.invisible)', + )) { + a.remove(); + } + }, + }); + return !!text; +} + +function getHTMLTextForDetectLang(content) { + return getHTMLText(content, { + preProcess: (dom) => { + // Remove anything that can skew the language detection + + // Remove .mention, .hashtag, pre, code, a:has(.invisible) + for (const a of dom.querySelectorAll( + '.mention, .hashtag, pre, code, a:has(.invisible)', + )) { + a.remove(); + } + + // Remove links that contains text that starts with https?:// + for (const a of dom.querySelectorAll('a')) { + const text = a.innerText.trim(); + if (text.startsWith('https://') || text.startsWith('http://')) { + a.remove(); + } + } + }, + }); +} + const HTTP_REGEX = /^http/i; const PostContent = /*memo(*/ @@ -343,32 +383,10 @@ function Status({ useEffect(() => { if (!content) return; if (_language) return; + if (languageAutoDetected) return; let timer; timer = setTimeout(async () => { - let detected = await detectLang( - getHTMLText(content, { - preProcess: (dom) => { - // Remove anything that can skew the language detection - - // Remove .mention, .hashtag, pre, code, a:has(.invisible) - dom - .querySelectorAll( - '.mention, .hashtag, pre, code, a:has(.invisible)', - ) - .forEach((a) => { - a.remove(); - }); - - // Remove links that contains text that starts with https?:// - dom.querySelectorAll('a').forEach((a) => { - const text = a.innerText.trim(); - if (text.startsWith('https://') || text.startsWith('http://')) { - a.remove(); - } - }); - }, - }), - ); + let detected = await detectLang(getHTMLTextForDetectLang(content)); setLanguageAutoDetected(detected); }, 1000); return () => clearTimeout(timer); @@ -2101,8 +2119,7 @@ function Status({ /> )} {(((enableTranslate || inlineTranslate) && - !!content.trim() && - !!getHTMLText(emojifyText(content, emojis)) && + isTranslateble(content) && differentLanguage) || forceTranslate) && ( l or <1>f" msgstr "" #: src/components/keyboard-shortcuts-help.jsx:164 -#: src/components/status.jsx:903 -#: src/components/status.jsx:2364 -#: src/components/status.jsx:2396 -#: src/components/status.jsx:2397 +#: src/components/status.jsx:921 +#: src/components/status.jsx:2381 +#: src/components/status.jsx:2413 +#: src/components/status.jsx:2414 msgid "Boost" msgstr "" @@ -1105,9 +1105,9 @@ msgid "<0>Shift + <1>b" msgstr "" #: src/components/keyboard-shortcuts-help.jsx:172 -#: src/components/status.jsx:988 -#: src/components/status.jsx:2421 -#: src/components/status.jsx:2422 +#: src/components/status.jsx:1006 +#: src/components/status.jsx:2438 +#: src/components/status.jsx:2439 msgid "Bookmark" msgstr "" @@ -1166,15 +1166,15 @@ msgid "Media description" msgstr "" #: src/components/media-alt-modal.jsx:57 -#: src/components/status.jsx:1032 -#: src/components/status.jsx:1059 +#: src/components/status.jsx:1050 +#: src/components/status.jsx:1077 #: src/components/translation-block.jsx:195 msgid "Translate" msgstr "" #: src/components/media-alt-modal.jsx:68 -#: src/components/status.jsx:1046 -#: src/components/status.jsx:1073 +#: src/components/status.jsx:1064 +#: src/components/status.jsx:1091 msgid "Speak" msgstr "" @@ -1211,9 +1211,9 @@ msgid "Filtered: {filterTitleStr}" msgstr "" #: src/components/media-post.jsx:133 -#: src/components/status.jsx:3511 -#: src/components/status.jsx:3607 -#: src/components/status.jsx:3685 +#: src/components/status.jsx:3528 +#: src/components/status.jsx:3624 +#: src/components/status.jsx:3702 #: src/components/timeline.jsx:973 #: src/pages/catchup.jsx:75 #: src/pages/catchup.jsx:1876 @@ -1501,8 +1501,8 @@ msgid "[Unknown notification type: {type}]" msgstr "" #: src/components/notification.jsx:434 -#: src/components/status.jsx:1002 -#: src/components/status.jsx:1012 +#: src/components/status.jsx:1020 +#: src/components/status.jsx:1030 msgid "Boosted/Liked by…" msgstr "" @@ -1524,7 +1524,7 @@ msgid "Learn more <0/>" msgstr "" #: src/components/notification.jsx:756 -#: src/components/status.jsx:211 +#: src/components/status.jsx:251 msgid "Read more →" msgstr "" @@ -1817,7 +1817,7 @@ msgid "Move down" msgstr "" #: src/components/shortcuts-settings.jsx:379 -#: src/components/status.jsx:1280 +#: src/components/status.jsx:1298 #: src/pages/list.jsx:170 msgid "Edit" msgstr "" @@ -2015,297 +2015,297 @@ msgstr "" msgid "Import/export settings from/to instance server (Very experimental)" msgstr "" -#: src/components/status.jsx:504 +#: src/components/status.jsx:522 msgid "<0/> <1>boosted" msgstr "" -#: src/components/status.jsx:603 +#: src/components/status.jsx:621 msgid "Sorry, your current logged-in instance can't interact with this post from another instance." msgstr "" -#: src/components/status.jsx:756 +#: src/components/status.jsx:774 msgid "Unliked @{0}'s post" msgstr "" -#: src/components/status.jsx:757 +#: src/components/status.jsx:775 msgid "Liked @{0}'s post" msgstr "" -#: src/components/status.jsx:796 +#: src/components/status.jsx:814 msgid "Unbookmarked @{0}'s post" msgstr "" -#: src/components/status.jsx:797 +#: src/components/status.jsx:815 msgid "Bookmarked @{0}'s post" msgstr "" -#: src/components/status.jsx:903 -#: src/components/status.jsx:965 -#: src/components/status.jsx:2364 -#: src/components/status.jsx:2396 +#: src/components/status.jsx:921 +#: src/components/status.jsx:983 +#: src/components/status.jsx:2381 +#: src/components/status.jsx:2413 msgid "Unboost" msgstr "" -#: src/components/status.jsx:919 -#: src/components/status.jsx:2379 +#: src/components/status.jsx:937 +#: src/components/status.jsx:2396 msgid "Quote" msgstr "" -#: src/components/status.jsx:927 -#: src/components/status.jsx:2388 +#: src/components/status.jsx:945 +#: src/components/status.jsx:2405 msgid "Some media have no descriptions." msgstr "" -#: src/components/status.jsx:934 +#: src/components/status.jsx:952 msgid "Old post (<0>{0})" msgstr "" -#: src/components/status.jsx:953 -#: src/components/status.jsx:1408 +#: src/components/status.jsx:971 +#: src/components/status.jsx:1426 msgid "Unboosted @{0}'s post" msgstr "" -#: src/components/status.jsx:954 -#: src/components/status.jsx:1409 +#: src/components/status.jsx:972 +#: src/components/status.jsx:1427 msgid "Boosted @{0}'s post" msgstr "" -#: src/components/status.jsx:966 +#: src/components/status.jsx:984 msgid "Boost…" msgstr "" -#: src/components/status.jsx:978 -#: src/components/status.jsx:1693 -#: src/components/status.jsx:2409 +#: src/components/status.jsx:996 +#: src/components/status.jsx:1711 +#: src/components/status.jsx:2426 msgid "Unlike" msgstr "" -#: src/components/status.jsx:979 -#: src/components/status.jsx:1693 -#: src/components/status.jsx:1694 -#: src/components/status.jsx:2409 -#: src/components/status.jsx:2410 +#: src/components/status.jsx:997 +#: src/components/status.jsx:1711 +#: src/components/status.jsx:1712 +#: src/components/status.jsx:2426 +#: src/components/status.jsx:2427 msgid "Like" msgstr "" -#: src/components/status.jsx:988 -#: src/components/status.jsx:2421 +#: src/components/status.jsx:1006 +#: src/components/status.jsx:2438 msgid "Unbookmark" msgstr "" -#: src/components/status.jsx:1096 +#: src/components/status.jsx:1114 msgid "View post by <0>@{0}" msgstr "" -#: src/components/status.jsx:1117 +#: src/components/status.jsx:1135 msgid "Show Edit History" msgstr "" -#: src/components/status.jsx:1120 +#: src/components/status.jsx:1138 msgid "Edited: {editedDateText}" msgstr "" -#: src/components/status.jsx:1187 -#: src/components/status.jsx:3188 +#: src/components/status.jsx:1205 +#: src/components/status.jsx:3205 msgid "Embed post" msgstr "" -#: src/components/status.jsx:1201 +#: src/components/status.jsx:1219 msgid "Conversation unmuted" msgstr "" -#: src/components/status.jsx:1201 +#: src/components/status.jsx:1219 msgid "Conversation muted" msgstr "" -#: src/components/status.jsx:1207 +#: src/components/status.jsx:1225 msgid "Unable to unmute conversation" msgstr "" -#: src/components/status.jsx:1208 +#: src/components/status.jsx:1226 msgid "Unable to mute conversation" msgstr "" -#: src/components/status.jsx:1217 +#: src/components/status.jsx:1235 msgid "Unmute conversation" msgstr "" -#: src/components/status.jsx:1224 +#: src/components/status.jsx:1242 msgid "Mute conversation" msgstr "" -#: src/components/status.jsx:1240 +#: src/components/status.jsx:1258 msgid "Post unpinned from profile" msgstr "" -#: src/components/status.jsx:1241 +#: src/components/status.jsx:1259 msgid "Post pinned to profile" msgstr "" -#: src/components/status.jsx:1246 +#: src/components/status.jsx:1264 msgid "Unable to unpin post" msgstr "" -#: src/components/status.jsx:1246 +#: src/components/status.jsx:1264 msgid "Unable to pin post" msgstr "" -#: src/components/status.jsx:1255 +#: src/components/status.jsx:1273 msgid "Unpin from profile" msgstr "" -#: src/components/status.jsx:1262 +#: src/components/status.jsx:1280 msgid "Pin to profile" msgstr "" -#: src/components/status.jsx:1291 +#: src/components/status.jsx:1309 msgid "Delete this post?" msgstr "" -#: src/components/status.jsx:1307 +#: src/components/status.jsx:1325 msgid "Post deleted" msgstr "" -#: src/components/status.jsx:1310 +#: src/components/status.jsx:1328 msgid "Unable to delete post" msgstr "" -#: src/components/status.jsx:1338 +#: src/components/status.jsx:1356 msgid "Report post…" msgstr "" -#: src/components/status.jsx:1694 -#: src/components/status.jsx:1730 -#: src/components/status.jsx:2410 +#: src/components/status.jsx:1712 +#: src/components/status.jsx:1748 +#: src/components/status.jsx:2427 msgid "Liked" msgstr "" -#: src/components/status.jsx:1727 -#: src/components/status.jsx:2397 +#: src/components/status.jsx:1745 +#: src/components/status.jsx:2414 msgid "Boosted" msgstr "" -#: src/components/status.jsx:1737 -#: src/components/status.jsx:2422 +#: src/components/status.jsx:1755 +#: src/components/status.jsx:2439 msgid "Bookmarked" msgstr "" -#: src/components/status.jsx:1741 +#: src/components/status.jsx:1759 msgid "Pinned" msgstr "" -#: src/components/status.jsx:1786 -#: src/components/status.jsx:2241 +#: src/components/status.jsx:1804 +#: src/components/status.jsx:2258 msgid "Deleted" msgstr "" -#: src/components/status.jsx:1827 +#: src/components/status.jsx:1845 msgid "{repliesCount, plural, one {# reply} other {# replies}}" msgstr "" -#: src/components/status.jsx:1916 +#: src/components/status.jsx:1934 msgid "Thread{0}" msgstr "" -#: src/components/status.jsx:1992 -#: src/components/status.jsx:2054 -#: src/components/status.jsx:2139 +#: src/components/status.jsx:2010 +#: src/components/status.jsx:2072 +#: src/components/status.jsx:2156 msgid "Show less" msgstr "" -#: src/components/status.jsx:1992 -#: src/components/status.jsx:2054 +#: src/components/status.jsx:2010 +#: src/components/status.jsx:2072 msgid "Show content" msgstr "" -#: src/components/status.jsx:2139 +#: src/components/status.jsx:2156 msgid "Show media" msgstr "" -#: src/components/status.jsx:2262 +#: src/components/status.jsx:2279 msgid "Edited" msgstr "" -#: src/components/status.jsx:2339 +#: src/components/status.jsx:2356 msgid "Comments" msgstr "" #. More from [Author] -#: src/components/status.jsx:2648 +#: src/components/status.jsx:2665 msgid "More from <0/>" msgstr "More from <0/>" -#: src/components/status.jsx:2949 +#: src/components/status.jsx:2966 msgid "Edit History" msgstr "" -#: src/components/status.jsx:2953 +#: src/components/status.jsx:2970 msgid "Failed to load history" msgstr "" -#: src/components/status.jsx:2958 +#: src/components/status.jsx:2975 msgid "Loading…" msgstr "" -#: src/components/status.jsx:3193 +#: src/components/status.jsx:3210 msgid "HTML Code" msgstr "" -#: src/components/status.jsx:3210 +#: src/components/status.jsx:3227 msgid "HTML code copied" msgstr "" -#: src/components/status.jsx:3213 +#: src/components/status.jsx:3230 msgid "Unable to copy HTML code" msgstr "" -#: src/components/status.jsx:3225 +#: src/components/status.jsx:3242 msgid "Media attachments:" msgstr "" -#: src/components/status.jsx:3247 +#: src/components/status.jsx:3264 msgid "Account Emojis:" msgstr "" -#: src/components/status.jsx:3278 -#: src/components/status.jsx:3323 +#: src/components/status.jsx:3295 +#: src/components/status.jsx:3340 msgid "static URL" msgstr "" -#: src/components/status.jsx:3292 +#: src/components/status.jsx:3309 msgid "Emojis:" msgstr "" -#: src/components/status.jsx:3337 +#: src/components/status.jsx:3354 msgid "Notes:" msgstr "" -#: src/components/status.jsx:3341 +#: src/components/status.jsx:3358 msgid "This is static, unstyled and scriptless. You may need to apply your own styles and edit as needed." msgstr "" -#: src/components/status.jsx:3347 +#: src/components/status.jsx:3364 msgid "Polls are not interactive, becomes a list with vote counts." msgstr "" -#: src/components/status.jsx:3352 +#: src/components/status.jsx:3369 msgid "Media attachments can be images, videos, audios or any file types." msgstr "" -#: src/components/status.jsx:3358 +#: src/components/status.jsx:3375 msgid "Post could be edited or deleted later." msgstr "" -#: src/components/status.jsx:3364 +#: src/components/status.jsx:3381 msgid "Preview" msgstr "" -#: src/components/status.jsx:3373 +#: src/components/status.jsx:3390 msgid "Note: This preview is lightly styled." msgstr "" #. [Name] [Visibility icon] boosted -#: src/components/status.jsx:3615 +#: src/components/status.jsx:3632 msgid "<0/> <1/> boosted" msgstr ""