Move diff language check to separate Task

This commit is contained in:
Lim Chee Aun 2024-09-26 11:21:57 +08:00
parent b76d2308eb
commit a19beffd20
2 changed files with 184 additions and 141 deletions

View file

@ -210,6 +210,25 @@ const detectLang = pmem(async (text) => {
const readMoreText = msg`Read more →`;
// All this work just to make sure this only lazy-run once
// Because first run is slow due to intl-localematcher
const DIFFERENT_LANG_CHECK = {};
const checkDifferentLanguage = (
language,
contentTranslationHideLanguages = [],
) => {
if (!language) return false;
const targetLanguage = getTranslateTargetLanguage(true);
const different =
language !== targetLanguage &&
!localeMatch([language], [targetLanguage]) &&
!contentTranslationHideLanguages.find(
(l) => language === l || localeMatch([language], [l]),
);
DIFFERENT_LANG_CHECK[language + contentTranslationHideLanguages] = true;
return different;
};
function Status({
statusID,
status,
@ -534,9 +553,9 @@ function Status({
const isSizeLarge = size === 'l';
const [forceTranslate, setForceTranslate] = useState(_forceTranslate);
const targetLanguage = getTranslateTargetLanguage(true);
const contentTranslationHideLanguages =
snapStates.settings.contentTranslationHideLanguages || [];
// const targetLanguage = getTranslateTargetLanguage(true);
// const contentTranslationHideLanguages =
// snapStates.settings.contentTranslationHideLanguages || [];
const { contentTranslation, contentTranslationAutoInline } =
snapStates.settings;
if (!contentTranslation) enableTranslate = false;
@ -781,13 +800,37 @@ function Status({
} catch (e) {}
};
const differentLanguage =
!!language &&
language !== targetLanguage &&
!localeMatch([language], [targetLanguage]) &&
!contentTranslationHideLanguages.find(
(l) => language === l || localeMatch([language], [l]),
);
// const differentLanguage =
// !!language &&
// language !== targetLanguage &&
// !localeMatch([language], [targetLanguage]) &&
// !contentTranslationHideLanguages.find(
// (l) => language === l || localeMatch([language], [l]),
// );
const contentTranslationHideLanguages =
snapStates.settings.contentTranslationHideLanguages || [];
const [differentLanguage, setDifferentLanguage] = useState(
DIFFERENT_LANG_CHECK[language + contentTranslationHideLanguages]
? checkDifferentLanguage(language, contentTranslationHideLanguages)
: false,
);
useEffect(() => {
if (
!language ||
differentLanguage ||
DIFFERENT_LANG_CHECK[language + contentTranslationHideLanguages]
) {
return;
}
let timeout = setTimeout(() => {
const different = checkDifferentLanguage(
language,
contentTranslationHideLanguages,
);
if (different) setDifferentLanguage(different);
}, 1);
return () => clearTimeout(timeout);
}, [language, differentLanguage, contentTranslationHideLanguages]);
const reblogIterator = useRef();
const favouriteIterator = useRef();

262
src/locales/en.po generated
View file

@ -32,7 +32,7 @@ msgstr ""
#: src/components/account-block.jsx:168
#: src/components/account-info.jsx:639
#: src/components/status.jsx:461
#: src/components/status.jsx:480
#: src/pages/catchup.jsx:1471
msgid "Group"
msgstr ""
@ -108,11 +108,11 @@ msgstr ""
#: src/components/compose.jsx:2463
#: src/components/media-alt-modal.jsx:45
#: src/components/media-modal.jsx:283
#: src/components/status.jsx:1657
#: src/components/status.jsx:1674
#: src/components/status.jsx:1798
#: src/components/status.jsx:2396
#: src/components/status.jsx:2399
#: src/components/status.jsx:1700
#: src/components/status.jsx:1717
#: src/components/status.jsx:1841
#: src/components/status.jsx:2439
#: src/components/status.jsx:2442
#: src/pages/account-statuses.jsx:528
#: src/pages/accounts.jsx:109
#: src/pages/hashtag.jsx:199
@ -181,7 +181,7 @@ msgid "Original"
msgstr ""
#: src/components/account-info.jsx:859
#: src/components/status.jsx:2187
#: src/components/status.jsx:2230
#: src/pages/catchup.jsx:71
#: src/pages/catchup.jsx:1445
#: src/pages/catchup.jsx:2056
@ -277,30 +277,30 @@ msgid "Add/Remove from Lists"
msgstr ""
#: src/components/account-info.jsx:1299
#: src/components/status.jsx:1100
#: src/components/status.jsx:1143
msgid "Link copied"
msgstr ""
#: src/components/account-info.jsx:1302
#: src/components/status.jsx:1103
#: src/components/status.jsx:1146
msgid "Unable to copy link"
msgstr ""
#: src/components/account-info.jsx:1308
#: src/components/shortcuts-settings.jsx:1056
#: src/components/status.jsx:1109
#: src/components/status.jsx:3171
#: src/components/status.jsx:1152
#: src/components/status.jsx:3214
msgid "Copy"
msgstr ""
#: src/components/account-info.jsx:1323
#: src/components/shortcuts-settings.jsx:1074
#: src/components/status.jsx:1125
#: src/components/status.jsx:1168
msgid "Sharing doesn't seem to work."
msgstr ""
#: src/components/account-info.jsx:1329
#: src/components/status.jsx:1131
#: src/components/status.jsx:1174
msgid "Share…"
msgstr ""
@ -417,9 +417,9 @@ msgstr ""
#: src/components/shortcuts-settings.jsx:227
#: src/components/shortcuts-settings.jsx:580
#: src/components/shortcuts-settings.jsx:780
#: src/components/status.jsx:2896
#: src/components/status.jsx:3135
#: src/components/status.jsx:3633
#: src/components/status.jsx:2939
#: src/components/status.jsx:3178
#: src/components/status.jsx:3676
#: src/pages/accounts.jsx:36
#: src/pages/catchup.jsx:1581
#: src/pages/filters.jsx:224
@ -605,7 +605,7 @@ msgid "Attachment #{i} failed"
msgstr ""
#: src/components/compose.jsx:1118
#: src/components/status.jsx:1983
#: src/components/status.jsx:2026
#: src/components/timeline.jsx:984
msgid "Content warning"
msgstr ""
@ -641,7 +641,7 @@ msgstr ""
#: src/components/compose.jsx:1185
#: src/components/status.jsx:97
#: src/components/status.jsx:1861
#: src/components/status.jsx:1904
msgid "Private mention"
msgstr ""
@ -671,10 +671,10 @@ msgstr ""
#: src/components/compose.jsx:1479
#: src/components/keyboard-shortcuts-help.jsx:143
#: src/components/status.jsx:852
#: src/components/status.jsx:1637
#: src/components/status.jsx:1638
#: src/components/status.jsx:2292
#: src/components/status.jsx:895
#: src/components/status.jsx:1680
#: src/components/status.jsx:1681
#: src/components/status.jsx:2335
msgid "Reply"
msgstr ""
@ -889,7 +889,7 @@ msgstr ""
#: src/components/drafts.jsx:127
#: src/components/list-add-edit.jsx:183
#: src/components/status.jsx:1272
#: src/components/status.jsx:1315
#: src/pages/filters.jsx:587
msgid "Delete…"
msgstr ""
@ -1089,10 +1089,10 @@ msgid "<0>l</0> or <1>f</1>"
msgstr ""
#: src/components/keyboard-shortcuts-help.jsx:164
#: src/components/status.jsx:860
#: src/components/status.jsx:2318
#: src/components/status.jsx:2350
#: src/components/status.jsx:2351
#: src/components/status.jsx:903
#: src/components/status.jsx:2361
#: src/components/status.jsx:2393
#: src/components/status.jsx:2394
msgid "Boost"
msgstr ""
@ -1101,9 +1101,9 @@ msgid "<0>Shift</0> + <1>b</1>"
msgstr ""
#: src/components/keyboard-shortcuts-help.jsx:172
#: src/components/status.jsx:945
#: src/components/status.jsx:2375
#: src/components/status.jsx:2376
#: src/components/status.jsx:988
#: src/components/status.jsx:2418
#: src/components/status.jsx:2419
msgid "Bookmark"
msgstr ""
@ -1162,15 +1162,15 @@ msgid "Media description"
msgstr ""
#: src/components/media-alt-modal.jsx:57
#: src/components/status.jsx:989
#: src/components/status.jsx:1016
#: src/components/status.jsx:1032
#: src/components/status.jsx:1059
#: src/components/translation-block.jsx:195
msgid "Translate"
msgstr ""
#: src/components/media-alt-modal.jsx:68
#: src/components/status.jsx:1003
#: src/components/status.jsx:1030
#: src/components/status.jsx:1046
#: src/components/status.jsx:1073
msgid "Speak"
msgstr ""
@ -1207,9 +1207,9 @@ msgid "Filtered: {filterTitleStr}"
msgstr ""
#: src/components/media-post.jsx:133
#: src/components/status.jsx:3463
#: src/components/status.jsx:3559
#: src/components/status.jsx:3637
#: src/components/status.jsx:3506
#: src/components/status.jsx:3602
#: src/components/status.jsx:3680
#: src/components/timeline.jsx:973
#: src/pages/catchup.jsx:75
#: src/pages/catchup.jsx:1876
@ -1489,8 +1489,8 @@ msgid "[Unknown notification type: {type}]"
msgstr ""
#: src/components/notification.jsx:433
#: src/components/status.jsx:959
#: src/components/status.jsx:969
#: src/components/status.jsx:1002
#: src/components/status.jsx:1012
msgid "Boosted/Liked by…"
msgstr ""
@ -1805,7 +1805,7 @@ msgid "Move down"
msgstr ""
#: src/components/shortcuts-settings.jsx:376
#: src/components/status.jsx:1237
#: src/components/status.jsx:1280
#: src/pages/list.jsx:170
msgid "Edit"
msgstr ""
@ -2003,297 +2003,297 @@ msgstr ""
msgid "Import/export settings from/to instance server (Very experimental)"
msgstr ""
#: src/components/status.jsx:485
#: src/components/status.jsx:504
msgid "<0/> <1>boosted</1>"
msgstr ""
#: src/components/status.jsx:584
#: src/components/status.jsx:603
msgid "Sorry, your current logged-in instance can't interact with this post from another instance."
msgstr ""
#: src/components/status.jsx:737
#: src/components/status.jsx:756
msgid "Unliked @{0}'s post"
msgstr "Unliked @{0}'s post"
#: src/components/status.jsx:738
#: src/components/status.jsx:757
msgid "Liked @{0}'s post"
msgstr "Liked @{0}'s post"
#: src/components/status.jsx:777
#: src/components/status.jsx:796
msgid "Unbookmarked @{0}'s post"
msgstr ""
#: src/components/status.jsx:778
#: src/components/status.jsx:797
msgid "Bookmarked @{0}'s post"
msgstr ""
#: src/components/status.jsx:860
#: src/components/status.jsx:922
#: src/components/status.jsx:2318
#: src/components/status.jsx:2350
#: src/components/status.jsx:903
#: src/components/status.jsx:965
#: src/components/status.jsx:2361
#: src/components/status.jsx:2393
msgid "Unboost"
msgstr ""
#: src/components/status.jsx:876
#: src/components/status.jsx:2333
#: src/components/status.jsx:919
#: src/components/status.jsx:2376
msgid "Quote"
msgstr ""
#: src/components/status.jsx:884
#: src/components/status.jsx:2342
#: src/components/status.jsx:927
#: src/components/status.jsx:2385
msgid "Some media have no descriptions."
msgstr ""
#: src/components/status.jsx:891
#: src/components/status.jsx:934
msgid "Old post (<0>{0}</0>)"
msgstr ""
#: src/components/status.jsx:910
#: src/components/status.jsx:1362
#: src/components/status.jsx:953
#: src/components/status.jsx:1405
msgid "Unboosted @{0}'s post"
msgstr ""
#: src/components/status.jsx:911
#: src/components/status.jsx:1363
#: src/components/status.jsx:954
#: src/components/status.jsx:1406
msgid "Boosted @{0}'s post"
msgstr ""
#: src/components/status.jsx:923
#: src/components/status.jsx:966
msgid "Boost…"
msgstr ""
#: src/components/status.jsx:935
#: src/components/status.jsx:1647
#: src/components/status.jsx:2363
#: src/components/status.jsx:978
#: src/components/status.jsx:1690
#: src/components/status.jsx:2406
msgid "Unlike"
msgstr ""
#: src/components/status.jsx:936
#: src/components/status.jsx:1647
#: src/components/status.jsx:1648
#: src/components/status.jsx:2363
#: src/components/status.jsx:2364
#: src/components/status.jsx:979
#: src/components/status.jsx:1690
#: src/components/status.jsx:1691
#: src/components/status.jsx:2406
#: src/components/status.jsx:2407
msgid "Like"
msgstr ""
#: src/components/status.jsx:945
#: src/components/status.jsx:2375
#: src/components/status.jsx:988
#: src/components/status.jsx:2418
msgid "Unbookmark"
msgstr ""
#: src/components/status.jsx:1053
#: src/components/status.jsx:1096
msgid "View post by <0>@{0}</0>"
msgstr ""
#: src/components/status.jsx:1074
#: src/components/status.jsx:1117
msgid "Show Edit History"
msgstr ""
#: src/components/status.jsx:1077
#: src/components/status.jsx:1120
msgid "Edited: {editedDateText}"
msgstr ""
#: src/components/status.jsx:1144
#: src/components/status.jsx:3140
#: src/components/status.jsx:1187
#: src/components/status.jsx:3183
msgid "Embed post"
msgstr ""
#: src/components/status.jsx:1158
#: src/components/status.jsx:1201
msgid "Conversation unmuted"
msgstr ""
#: src/components/status.jsx:1158
#: src/components/status.jsx:1201
msgid "Conversation muted"
msgstr ""
#: src/components/status.jsx:1164
#: src/components/status.jsx:1207
msgid "Unable to unmute conversation"
msgstr ""
#: src/components/status.jsx:1165
#: src/components/status.jsx:1208
msgid "Unable to mute conversation"
msgstr ""
#: src/components/status.jsx:1174
#: src/components/status.jsx:1217
msgid "Unmute conversation"
msgstr ""
#: src/components/status.jsx:1181
#: src/components/status.jsx:1224
msgid "Mute conversation"
msgstr ""
#: src/components/status.jsx:1197
#: src/components/status.jsx:1240
msgid "Post unpinned from profile"
msgstr ""
#: src/components/status.jsx:1198
#: src/components/status.jsx:1241
msgid "Post pinned to profile"
msgstr ""
#: src/components/status.jsx:1203
#: src/components/status.jsx:1246
msgid "Unable to unpin post"
msgstr ""
#: src/components/status.jsx:1203
#: src/components/status.jsx:1246
msgid "Unable to pin post"
msgstr ""
#: src/components/status.jsx:1212
#: src/components/status.jsx:1255
msgid "Unpin from profile"
msgstr ""
#: src/components/status.jsx:1219
#: src/components/status.jsx:1262
msgid "Pin to profile"
msgstr ""
#: src/components/status.jsx:1248
#: src/components/status.jsx:1291
msgid "Delete this post?"
msgstr ""
#: src/components/status.jsx:1261
#: src/components/status.jsx:1304
msgid "Post deleted"
msgstr ""
#: src/components/status.jsx:1264
#: src/components/status.jsx:1307
msgid "Unable to delete post"
msgstr ""
#: src/components/status.jsx:1292
#: src/components/status.jsx:1335
msgid "Report post…"
msgstr ""
#: src/components/status.jsx:1648
#: src/components/status.jsx:1684
#: src/components/status.jsx:2364
#: src/components/status.jsx:1691
#: src/components/status.jsx:1727
#: src/components/status.jsx:2407
msgid "Liked"
msgstr ""
#: src/components/status.jsx:1681
#: src/components/status.jsx:2351
#: src/components/status.jsx:1724
#: src/components/status.jsx:2394
msgid "Boosted"
msgstr ""
#: src/components/status.jsx:1691
#: src/components/status.jsx:2376
#: src/components/status.jsx:1734
#: src/components/status.jsx:2419
msgid "Bookmarked"
msgstr ""
#: src/components/status.jsx:1695
#: src/components/status.jsx:1738
msgid "Pinned"
msgstr ""
#: src/components/status.jsx:1740
#: src/components/status.jsx:2195
#: src/components/status.jsx:1783
#: src/components/status.jsx:2238
msgid "Deleted"
msgstr ""
#: src/components/status.jsx:1781
#: src/components/status.jsx:1824
msgid "{repliesCount, plural, one {# reply} other {# replies}}"
msgstr ""
#: src/components/status.jsx:1870
#: src/components/status.jsx:1913
msgid "Thread{0}"
msgstr ""
#: src/components/status.jsx:1946
#: src/components/status.jsx:2008
#: src/components/status.jsx:2093
#: src/components/status.jsx:1989
#: src/components/status.jsx:2051
#: src/components/status.jsx:2136
msgid "Show less"
msgstr ""
#: src/components/status.jsx:1946
#: src/components/status.jsx:2008
#: src/components/status.jsx:1989
#: src/components/status.jsx:2051
msgid "Show content"
msgstr ""
#: src/components/status.jsx:2093
#: src/components/status.jsx:2136
msgid "Show media"
msgstr ""
#: src/components/status.jsx:2216
#: src/components/status.jsx:2259
msgid "Edited"
msgstr ""
#: src/components/status.jsx:2293
#: src/components/status.jsx:2336
msgid "Comments"
msgstr ""
#. More from [Author]
#: src/components/status.jsx:2602
#: src/components/status.jsx:2645
msgid "More from <0/>"
msgstr "More from <0/>"
#: src/components/status.jsx:2901
#: src/components/status.jsx:2944
msgid "Edit History"
msgstr ""
#: src/components/status.jsx:2905
#: src/components/status.jsx:2948
msgid "Failed to load history"
msgstr ""
#: src/components/status.jsx:2910
#: src/components/status.jsx:2953
msgid "Loading…"
msgstr ""
#: src/components/status.jsx:3145
#: src/components/status.jsx:3188
msgid "HTML Code"
msgstr ""
#: src/components/status.jsx:3162
#: src/components/status.jsx:3205
msgid "HTML code copied"
msgstr ""
#: src/components/status.jsx:3165
#: src/components/status.jsx:3208
msgid "Unable to copy HTML code"
msgstr ""
#: src/components/status.jsx:3177
#: src/components/status.jsx:3220
msgid "Media attachments:"
msgstr ""
#: src/components/status.jsx:3199
#: src/components/status.jsx:3242
msgid "Account Emojis:"
msgstr ""
#: src/components/status.jsx:3230
#: src/components/status.jsx:3275
#: src/components/status.jsx:3273
#: src/components/status.jsx:3318
msgid "static URL"
msgstr ""
#: src/components/status.jsx:3244
#: src/components/status.jsx:3287
msgid "Emojis:"
msgstr ""
#: src/components/status.jsx:3289
#: src/components/status.jsx:3332
msgid "Notes:"
msgstr ""
#: src/components/status.jsx:3293
#: src/components/status.jsx:3336
msgid "This is static, unstyled and scriptless. You may need to apply your own styles and edit as needed."
msgstr ""
#: src/components/status.jsx:3299
#: src/components/status.jsx:3342
msgid "Polls are not interactive, becomes a list with vote counts."
msgstr ""
#: src/components/status.jsx:3304
#: src/components/status.jsx:3347
msgid "Media attachments can be images, videos, audios or any file types."
msgstr ""
#: src/components/status.jsx:3310
#: src/components/status.jsx:3353
msgid "Post could be edited or deleted later."
msgstr ""
#: src/components/status.jsx:3316
#: src/components/status.jsx:3359
msgid "Preview"
msgstr ""
#: src/components/status.jsx:3325
#: src/components/status.jsx:3368
msgid "Note: This preview is lightly styled."
msgstr ""
#. [Name] [Visibility icon] boosted
#: src/components/status.jsx:3567
#: src/components/status.jsx:3610
msgid "<0/> <1/> boosted"
msgstr ""