From 618156bcacecebffa05653e196935900cb8b8d6c Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Thu, 27 Feb 2025 17:16:29 +0800 Subject: [PATCH] Fix different language detection not working properly --- src/components/status.jsx | 27 +++- src/locales/en.po | 262 +++++++++++++++++++------------------- 2 files changed, 151 insertions(+), 138 deletions(-) diff --git a/src/components/status.jsx b/src/components/status.jsx index 999862de..48c65b26 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -154,7 +154,15 @@ function isTranslateble(content) { return !!text; } -function getHTMLTextForDetectLang(content) { +function getHTMLTextForDetectLang(content, emojis) { + if (emojis?.length) { + const emojisRegex = new RegExp( + `:(${emojis.map((e) => e.shortcode).join('|')}):`, + 'g', + ); + content = content.replace(emojisRegex, ''); + } + return getHTMLText(content, { preProcess: (dom) => { // Remove anything that can skew the language detection @@ -402,7 +410,9 @@ function Status({ if (languageAutoDetected) return; let timer; timer = setTimeout(async () => { - let detected = await detectLang(getHTMLTextForDetectLang(content)); + let detected = await detectLang( + getHTMLTextForDetectLang(content, emojis), + ); setLanguageAutoDetected(detected); }, 1000); return () => clearTimeout(timer); @@ -844,16 +854,19 @@ function Status({ const contentTranslationHideLanguages = snapStates.settings.contentTranslationHideLanguages || []; const [differentLanguage, setDifferentLanguage] = useState( - DIFFERENT_LANG_CHECK[language + contentTranslationHideLanguages] - ? checkDifferentLanguage(language, contentTranslationHideLanguages) - : false, + () => + DIFFERENT_LANG_CHECK[language + contentTranslationHideLanguages] || + checkDifferentLanguage(language, contentTranslationHideLanguages), ); useEffect(() => { + if (!language || differentLanguage) { + return; + } if ( - !language || - differentLanguage || + !differentLanguage && DIFFERENT_LANG_CHECK[language + contentTranslationHideLanguages] ) { + setDifferentLanguage(true); return; } let timeout = setTimeout(() => { diff --git a/src/locales/en.po b/src/locales/en.po index d1ffbc74..95024756 100644 --- a/src/locales/en.po +++ b/src/locales/en.po @@ -34,7 +34,7 @@ msgstr "" #: src/components/account-block.jsx:169 #: src/components/account-info.jsx:664 -#: src/components/status.jsx:514 +#: src/components/status.jsx:524 msgid "Group" msgstr "" @@ -111,11 +111,11 @@ msgstr "" #: src/components/compose.jsx:2696 #: src/components/media-alt-modal.jsx:46 #: src/components/media-modal.jsx:358 -#: src/components/status.jsx:1734 -#: src/components/status.jsx:1751 -#: src/components/status.jsx:1876 -#: src/components/status.jsx:2481 -#: src/components/status.jsx:2484 +#: src/components/status.jsx:1747 +#: src/components/status.jsx:1764 +#: src/components/status.jsx:1889 +#: src/components/status.jsx:2494 +#: src/components/status.jsx:2497 #: src/pages/account-statuses.jsx:523 #: src/pages/accounts.jsx:110 #: src/pages/hashtag.jsx:200 @@ -197,7 +197,7 @@ msgid "Original" msgstr "" #: src/components/account-info.jsx:887 -#: src/components/status.jsx:2267 +#: src/components/status.jsx:2280 #: src/pages/catchup.jsx:71 #: src/pages/catchup.jsx:1445 #: src/pages/catchup.jsx:2058 @@ -294,30 +294,30 @@ msgid "Add/Remove from Lists" msgstr "" #: src/components/account-info.jsx:1327 -#: src/components/status.jsx:1174 +#: src/components/status.jsx:1187 msgid "Link copied" msgstr "" #: src/components/account-info.jsx:1330 -#: src/components/status.jsx:1177 +#: src/components/status.jsx:1190 msgid "Unable to copy link" msgstr "" #: src/components/account-info.jsx:1336 #: src/components/shortcuts-settings.jsx:1059 -#: src/components/status.jsx:1183 -#: src/components/status.jsx:3260 +#: src/components/status.jsx:1196 +#: src/components/status.jsx:3273 msgid "Copy" msgstr "" #: src/components/account-info.jsx:1351 #: src/components/shortcuts-settings.jsx:1077 -#: src/components/status.jsx:1199 +#: src/components/status.jsx:1212 msgid "Sharing doesn't seem to work." msgstr "" #: src/components/account-info.jsx:1357 -#: src/components/status.jsx:1205 +#: src/components/status.jsx:1218 msgid "Share…" msgstr "" @@ -436,9 +436,9 @@ msgstr "" #: src/components/shortcuts-settings.jsx:230 #: src/components/shortcuts-settings.jsx:583 #: src/components/shortcuts-settings.jsx:783 -#: src/components/status.jsx:2984 -#: src/components/status.jsx:3224 -#: src/components/status.jsx:3724 +#: src/components/status.jsx:2997 +#: src/components/status.jsx:3237 +#: src/components/status.jsx:3737 #: src/pages/accounts.jsx:37 #: src/pages/catchup.jsx:1581 #: src/pages/filters.jsx:224 @@ -664,7 +664,7 @@ msgid "Attachment #{i} failed" msgstr "Attachment #{i} failed" #: src/components/compose.jsx:1206 -#: src/components/status.jsx:2062 +#: src/components/status.jsx:2075 #: src/components/timeline.jsx:989 msgid "Content warning" msgstr "" @@ -700,7 +700,7 @@ msgstr "" #: src/components/compose.jsx:1273 #: src/components/status.jsx:97 -#: src/components/status.jsx:1940 +#: src/components/status.jsx:1953 msgid "Private mention" msgstr "" @@ -737,10 +737,10 @@ msgstr "Schedule" #: src/components/compose.jsx:1627 #: src/components/keyboard-shortcuts-help.jsx:154 -#: src/components/status.jsx:948 -#: src/components/status.jsx:1714 -#: src/components/status.jsx:1715 -#: src/components/status.jsx:2385 +#: src/components/status.jsx:961 +#: src/components/status.jsx:1727 +#: src/components/status.jsx:1728 +#: src/components/status.jsx:2398 msgid "Reply" msgstr "" @@ -972,7 +972,7 @@ msgstr "" #: src/components/drafts.jsx:128 #: src/components/list-add-edit.jsx:186 -#: src/components/status.jsx:1349 +#: src/components/status.jsx:1362 #: src/pages/filters.jsx:587 #: src/pages/scheduled-posts.jsx:367 msgid "Delete…" @@ -1181,10 +1181,10 @@ msgid "<0>l or <1>f" msgstr "" #: src/components/keyboard-shortcuts-help.jsx:175 -#: src/components/status.jsx:956 -#: src/components/status.jsx:2412 -#: src/components/status.jsx:2435 -#: src/components/status.jsx:2436 +#: src/components/status.jsx:969 +#: src/components/status.jsx:2425 +#: src/components/status.jsx:2448 +#: src/components/status.jsx:2449 msgid "Boost" msgstr "" @@ -1193,9 +1193,9 @@ msgid "<0>Shift + <1>b" msgstr "" #: src/components/keyboard-shortcuts-help.jsx:183 -#: src/components/status.jsx:1019 -#: src/components/status.jsx:2460 -#: src/components/status.jsx:2461 +#: src/components/status.jsx:1032 +#: src/components/status.jsx:2473 +#: src/components/status.jsx:2474 msgid "Bookmark" msgstr "" @@ -1254,15 +1254,15 @@ msgid "Media description" msgstr "" #: src/components/media-alt-modal.jsx:58 -#: src/components/status.jsx:1063 -#: src/components/status.jsx:1090 +#: src/components/status.jsx:1076 +#: src/components/status.jsx:1103 #: src/components/translation-block.jsx:196 msgid "Translate" msgstr "" #: src/components/media-alt-modal.jsx:69 -#: src/components/status.jsx:1077 -#: src/components/status.jsx:1104 +#: src/components/status.jsx:1090 +#: src/components/status.jsx:1117 msgid "Speak" msgstr "" @@ -1299,9 +1299,9 @@ msgid "Filtered: {filterTitleStr}" msgstr "" #: src/components/media-post.jsx:134 -#: src/components/status.jsx:3554 -#: src/components/status.jsx:3650 -#: src/components/status.jsx:3728 +#: src/components/status.jsx:3567 +#: src/components/status.jsx:3663 +#: src/components/status.jsx:3741 #: src/components/timeline.jsx:978 #: src/pages/catchup.jsx:75 #: src/pages/catchup.jsx:1877 @@ -1619,8 +1619,8 @@ msgid "[Unknown notification type: {type}]" msgstr "" #: src/components/notification.jsx:441 -#: src/components/status.jsx:1033 -#: src/components/status.jsx:1043 +#: src/components/status.jsx:1046 +#: src/components/status.jsx:1056 msgid "Boosted/Liked by…" msgstr "" @@ -1646,7 +1646,7 @@ msgid "View #Wrapstodon" msgstr "View #Wrapstodon" #: src/components/notification.jsx:770 -#: src/components/status.jsx:267 +#: src/components/status.jsx:275 msgid "Read more →" msgstr "" @@ -1948,7 +1948,7 @@ msgid "Move down" msgstr "" #: src/components/shortcuts-settings.jsx:379 -#: src/components/status.jsx:1311 +#: src/components/status.jsx:1324 #: src/pages/list.jsx:171 msgid "Edit" msgstr "" @@ -2147,314 +2147,314 @@ msgstr "" msgid "Import/export settings from/to instance server (Very experimental)" msgstr "" -#: src/components/status.jsx:538 +#: src/components/status.jsx:548 msgid "<0/> <1>boosted" msgstr "" -#: src/components/status.jsx:637 +#: src/components/status.jsx:647 msgid "Sorry, your current logged-in instance can't interact with this post from another instance." msgstr "" #. placeholder {0}: username || acct -#: src/components/status.jsx:790 +#: src/components/status.jsx:800 msgid "Unliked @{0}'s post" msgstr "" #. placeholder {1}: username || acct -#: src/components/status.jsx:791 +#: src/components/status.jsx:801 msgid "Liked @{1}'s post" msgstr "Liked @{1}'s post" #. placeholder {2}: username || acct -#: src/components/status.jsx:830 +#: src/components/status.jsx:840 msgid "Unbookmarked @{2}'s post" msgstr "Unbookmarked @{2}'s post" #. placeholder {3}: username || acct -#: src/components/status.jsx:831 +#: src/components/status.jsx:841 msgid "Bookmarked @{3}'s post" msgstr "Bookmarked @{3}'s post" -#: src/components/status.jsx:925 +#: src/components/status.jsx:938 msgid "Some media have no descriptions." msgstr "" #. placeholder {0}: rtf.format(-statusMonthsAgo, 'month') -#: src/components/status.jsx:932 +#: src/components/status.jsx:945 msgid "Old post (<0>{0})" msgstr "" -#: src/components/status.jsx:956 -#: src/components/status.jsx:996 -#: src/components/status.jsx:2412 -#: src/components/status.jsx:2435 +#: src/components/status.jsx:969 +#: src/components/status.jsx:1009 +#: src/components/status.jsx:2425 +#: src/components/status.jsx:2448 msgid "Unboost" msgstr "" -#: src/components/status.jsx:972 -#: src/components/status.jsx:2427 +#: src/components/status.jsx:985 +#: src/components/status.jsx:2440 msgid "Quote" msgstr "" #. placeholder {4}: username || acct -#: src/components/status.jsx:984 +#: src/components/status.jsx:997 msgid "Unboosted @{4}'s post" msgstr "Unboosted @{4}'s post" #. placeholder {5}: username || acct -#: src/components/status.jsx:985 +#: src/components/status.jsx:998 msgid "Boosted @{5}'s post" msgstr "Boosted @{5}'s post" -#: src/components/status.jsx:997 +#: src/components/status.jsx:1010 msgid "Boost…" msgstr "" -#: src/components/status.jsx:1009 -#: src/components/status.jsx:1724 -#: src/components/status.jsx:2448 +#: src/components/status.jsx:1022 +#: src/components/status.jsx:1737 +#: src/components/status.jsx:2461 msgid "Unlike" msgstr "" -#: src/components/status.jsx:1010 -#: src/components/status.jsx:1724 -#: src/components/status.jsx:1725 -#: src/components/status.jsx:2448 -#: src/components/status.jsx:2449 +#: src/components/status.jsx:1023 +#: src/components/status.jsx:1737 +#: src/components/status.jsx:1738 +#: src/components/status.jsx:2461 +#: src/components/status.jsx:2462 msgid "Like" msgstr "" -#: src/components/status.jsx:1019 -#: src/components/status.jsx:2460 +#: src/components/status.jsx:1032 +#: src/components/status.jsx:2473 msgid "Unbookmark" msgstr "" #. placeholder {0}: username || acct -#: src/components/status.jsx:1127 +#: src/components/status.jsx:1140 msgid "View post by <0>@{0}" msgstr "" -#: src/components/status.jsx:1148 +#: src/components/status.jsx:1161 msgid "Show Edit History" msgstr "" -#: src/components/status.jsx:1151 +#: src/components/status.jsx:1164 msgid "Edited: {editedDateText}" msgstr "" -#: src/components/status.jsx:1218 -#: src/components/status.jsx:3229 +#: src/components/status.jsx:1231 +#: src/components/status.jsx:3242 msgid "Embed post" msgstr "" -#: src/components/status.jsx:1232 +#: src/components/status.jsx:1245 msgid "Conversation unmuted" msgstr "" -#: src/components/status.jsx:1232 +#: src/components/status.jsx:1245 msgid "Conversation muted" msgstr "" -#: src/components/status.jsx:1238 +#: src/components/status.jsx:1251 msgid "Unable to unmute conversation" msgstr "" -#: src/components/status.jsx:1239 +#: src/components/status.jsx:1252 msgid "Unable to mute conversation" msgstr "" -#: src/components/status.jsx:1248 +#: src/components/status.jsx:1261 msgid "Unmute conversation" msgstr "" -#: src/components/status.jsx:1255 +#: src/components/status.jsx:1268 msgid "Mute conversation" msgstr "" -#: src/components/status.jsx:1271 +#: src/components/status.jsx:1284 msgid "Post unpinned from profile" msgstr "" -#: src/components/status.jsx:1272 +#: src/components/status.jsx:1285 msgid "Post pinned to profile" msgstr "" -#: src/components/status.jsx:1277 +#: src/components/status.jsx:1290 msgid "Unable to unpin post" msgstr "" -#: src/components/status.jsx:1277 +#: src/components/status.jsx:1290 msgid "Unable to pin post" msgstr "" -#: src/components/status.jsx:1286 +#: src/components/status.jsx:1299 msgid "Unpin from profile" msgstr "" -#: src/components/status.jsx:1293 +#: src/components/status.jsx:1306 msgid "Pin to profile" msgstr "" -#: src/components/status.jsx:1322 +#: src/components/status.jsx:1335 msgid "Delete this post?" msgstr "" -#: src/components/status.jsx:1338 +#: src/components/status.jsx:1351 msgid "Post deleted" msgstr "" -#: src/components/status.jsx:1341 +#: src/components/status.jsx:1354 msgid "Unable to delete post" msgstr "" -#: src/components/status.jsx:1369 +#: src/components/status.jsx:1382 msgid "Report post…" msgstr "" #. placeholder {6}: username || acct -#: src/components/status.jsx:1439 +#: src/components/status.jsx:1452 msgid "Unboosted @{6}'s post" msgstr "Unboosted @{6}'s post" #. placeholder {7}: username || acct -#: src/components/status.jsx:1440 +#: src/components/status.jsx:1453 msgid "Boosted @{7}'s post" msgstr "Boosted @{7}'s post" -#: src/components/status.jsx:1725 -#: src/components/status.jsx:1761 -#: src/components/status.jsx:2449 +#: src/components/status.jsx:1738 +#: src/components/status.jsx:1774 +#: src/components/status.jsx:2462 msgid "Liked" msgstr "" -#: src/components/status.jsx:1758 -#: src/components/status.jsx:2436 +#: src/components/status.jsx:1771 +#: src/components/status.jsx:2449 msgid "Boosted" msgstr "" -#: src/components/status.jsx:1768 -#: src/components/status.jsx:2461 +#: src/components/status.jsx:1781 +#: src/components/status.jsx:2474 msgid "Bookmarked" msgstr "" -#: src/components/status.jsx:1772 +#: src/components/status.jsx:1785 msgid "Pinned" msgstr "" -#: src/components/status.jsx:1818 -#: src/components/status.jsx:2275 +#: src/components/status.jsx:1831 +#: src/components/status.jsx:2288 msgid "Deleted" msgstr "" -#: src/components/status.jsx:1859 +#: src/components/status.jsx:1872 msgid "{repliesCount, plural, one {# reply} other {# replies}}" msgstr "" #. placeholder {0}: snapStates.statusThreadNumber[sKey] ? ` ${snapStates.statusThreadNumber[sKey]}/X` : '' -#: src/components/status.jsx:1949 +#: src/components/status.jsx:1962 msgid "Thread{0}" msgstr "" -#: src/components/status.jsx:2025 -#: src/components/status.jsx:2087 -#: src/components/status.jsx:2172 +#: src/components/status.jsx:2038 +#: src/components/status.jsx:2100 +#: src/components/status.jsx:2185 msgid "Show less" msgstr "" -#: src/components/status.jsx:2025 -#: src/components/status.jsx:2087 +#: src/components/status.jsx:2038 +#: src/components/status.jsx:2100 msgid "Show content" msgstr "" -#: src/components/status.jsx:2172 +#: src/components/status.jsx:2185 msgid "Show media" msgstr "" -#: src/components/status.jsx:2309 +#: src/components/status.jsx:2322 msgid "Edited" msgstr "" -#: src/components/status.jsx:2386 +#: src/components/status.jsx:2399 msgid "Comments" msgstr "" #. More from [Author] -#: src/components/status.jsx:2687 +#: src/components/status.jsx:2700 msgid "More from <0/>" msgstr "More from <0/>" -#: src/components/status.jsx:2989 +#: src/components/status.jsx:3002 msgid "Edit History" msgstr "" -#: src/components/status.jsx:2993 +#: src/components/status.jsx:3006 msgid "Failed to load history" msgstr "" -#: src/components/status.jsx:2998 +#: src/components/status.jsx:3011 #: src/pages/annual-report.jsx:45 msgid "Loading…" msgstr "" -#: src/components/status.jsx:3234 +#: src/components/status.jsx:3247 msgid "HTML Code" msgstr "" -#: src/components/status.jsx:3251 +#: src/components/status.jsx:3264 msgid "HTML code copied" msgstr "" -#: src/components/status.jsx:3254 +#: src/components/status.jsx:3267 msgid "Unable to copy HTML code" msgstr "" -#: src/components/status.jsx:3266 +#: src/components/status.jsx:3279 msgid "Media attachments:" msgstr "" -#: src/components/status.jsx:3288 +#: src/components/status.jsx:3301 msgid "Account Emojis:" msgstr "" -#: src/components/status.jsx:3319 -#: src/components/status.jsx:3364 +#: src/components/status.jsx:3332 +#: src/components/status.jsx:3377 msgid "static URL" msgstr "" -#: src/components/status.jsx:3333 +#: src/components/status.jsx:3346 msgid "Emojis:" msgstr "" -#: src/components/status.jsx:3378 +#: src/components/status.jsx:3391 msgid "Notes:" msgstr "" -#: src/components/status.jsx:3382 +#: src/components/status.jsx:3395 msgid "This is static, unstyled and scriptless. You may need to apply your own styles and edit as needed." msgstr "" -#: src/components/status.jsx:3388 +#: src/components/status.jsx:3401 msgid "Polls are not interactive, becomes a list with vote counts." msgstr "" -#: src/components/status.jsx:3393 +#: src/components/status.jsx:3406 msgid "Media attachments can be images, videos, audios or any file types." msgstr "" -#: src/components/status.jsx:3399 +#: src/components/status.jsx:3412 msgid "Post could be edited or deleted later." msgstr "" -#: src/components/status.jsx:3405 +#: src/components/status.jsx:3418 msgid "Preview" msgstr "" -#: src/components/status.jsx:3414 +#: src/components/status.jsx:3427 msgid "Note: This preview is lightly styled." msgstr "" #. [Name] [Visibility icon] boosted -#: src/components/status.jsx:3658 +#: src/components/status.jsx:3671 msgid "<0/> <1/> boosted" msgstr ""