Skip to content

Commit 9bece90

Browse files
authored
Merge pull request #428 from cofacts/fix-rtf
Fix when Intl.RelativeTimeFormat is not available
2 parents 82b15ed + da4f91b commit 9bece90

File tree

2 files changed

+56
-36
lines changed

2 files changed

+56
-36
lines changed

components/Infos/TimeInfo.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { useEffect, useState } from 'react';
2+
import { t } from 'ttag';
13
import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
2-
import Tooltip from 'components/Tooltip';
34
import isValid from 'date-fns/isValid';
4-
import { useEffect, useState } from 'react';
5+
6+
import { formatDistanceToNow } from 'lib/dateWithLocale';
7+
import Tooltip from 'components/Tooltip';
58

69
const locale = (process.env.LOCALE || 'en_US').replace('_', '-');
710

@@ -31,16 +34,24 @@ function formatDateAbsolute(
3134
return dtf.format(date);
3235
}
3336

34-
const rtf = new Intl.RelativeTimeFormat(locale, {
35-
style: 'narrow',
36-
numeric: 'auto',
37-
});
37+
const rtf = Intl.RelativeTimeFormat
38+
? new Intl.RelativeTimeFormat(locale, {
39+
style: 'narrow',
40+
numeric: 'auto',
41+
})
42+
: undefined;
3843

3944
/**
4045
* Formats date as a relative time (e.g. X days ago).
4146
* Works best if date is in the past.
4247
*/
4348
function formatDateRelative(date) {
49+
/* istanbul ignore if */
50+
if (!rtf) {
51+
const formatted = formatDistanceToNow(date);
52+
return t`${formatted} ago`;
53+
}
54+
4455
const now = new Date();
4556
const secsAgo = (now - date) / 1000;
4657
const minsAgo = secsAgo / 60;

i18n/zh_TW.po

+39-30
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ msgid "About"
1212
msgstr "關於"
1313

1414
#: components/ReportPage/SectionEcosystem.js:175
15-
#: pages/article/[id].js:305
15+
#: pages/article/[id].js:290
1616
#: pages/reply/[id].js:246
1717
msgid "Cofacts"
1818
msgstr "Cofacts 真的假的"
1919

2020
#: components/ArticleCategories/DownVoteDialog.js:98
2121
#: components/NewReplySection/Mobile.js:138
2222
#: components/ProfilePage/EditAvatarDialog.js:236
23-
#: components/ProfilePage/EditProfileDialog.js:88
23+
#: components/ProfilePage/EditProfileDialog.js:93
2424
msgid "Cancel"
2525
msgstr "取消"
2626

@@ -139,7 +139,7 @@ msgstr "刪除"
139139
#: components/CreateReplyRequestForm/CreateReplyRequestForm.js:132
140140
#: components/NewReplySection/ReplyForm/Submit.js:28
141141
#: components/ProfilePage/EditAvatarDialog.js:241
142-
#: components/ProfilePage/EditProfileDialog.js:93
142+
#: components/ProfilePage/EditProfileDialog.js:98
143143
msgid "Submit"
144144
msgstr "送出"
145145

@@ -148,7 +148,7 @@ msgstr "送出"
148148
msgid "Thank you for the feedback."
149149
msgstr "感謝您的意見。"
150150

151-
#: pages/article/[id].js:225
151+
#: pages/article/[id].js:216
152152
msgid "Your reply has been submitted."
153153
msgstr "已經送出回應。"
154154

@@ -166,7 +166,7 @@ msgstr "搜尋"
166166
msgid "Searching for messages and replies containing “${ variables.query }”..."
167167
msgstr "正在搜尋含有「${ variables.query }」的訊息與回應⋯⋯"
168168

169-
#: components/AppLayout/LoginModal.js:107
169+
#: components/AppLayout/LoginModal.js:109
170170
msgid "Login / Signup"
171171
msgstr "登入/註冊"
172172

@@ -207,7 +207,7 @@ msgid "someone"
207207
msgstr "有人"
208208

209209
#: components/LandingPage/Stats.js:146
210-
#. we hold ~
210+
#. we hold ~
211211
msgid "a gathering of editors."
212212
msgstr "編輯小聚"
213213

@@ -239,15 +239,15 @@ msgid ""
239239
"fighting mis/disinformation in Taiwan."
240240
msgstr "「Cofacts 真的假的」是一套連結網路訊息與查證訊息的協作型系統,試圖對假訊息問題作出草根應對。"
241241

242-
#: components/ProfilePage/ProfilePage.js:97
243-
#: pages/article/[id].js:262
244-
#: pages/article/[id].js:266
242+
#: components/ProfilePage/ProfilePage.js:98
243+
#: pages/article/[id].js:253
244+
#: pages/article/[id].js:257
245245
#: pages/reply/[id].js:200
246246
#: pages/reply/[id].js:204
247247
msgid "Loading"
248248
msgstr "載入中"
249249

250-
#: pages/article/[id].js:277
250+
#: pages/article/[id].js:268
251251
#: pages/reply/[id].js:215
252252
msgid "Not found"
253253
msgstr "找不到此頁面"
@@ -256,7 +256,7 @@ msgstr "找不到此頁面"
256256
msgid "Reply does not exist"
257257
msgstr "此回應不存在"
258258

259-
#: pages/article/[id].js:281
259+
#: pages/article/[id].js:272
260260
msgid "Message does not exist"
261261
msgstr "此訊息不存在"
262262

@@ -492,17 +492,17 @@ msgstr[0] "被回報 ${ replyRequestCount } 次"
492492
msgid "Searching"
493493
msgstr "正在搜尋"
494494

495-
#: pages/article/[id].js:313
495+
#: pages/article/[id].js:298
496496
#, javascript-format
497497
msgid "${ replyRequestCount } person report this message"
498498
msgid_plural "${ replyRequestCount } people report this message"
499499
msgstr[0] "有 ${ replyRequestCount } 人想知道以下訊息的真實性"
500500

501-
#: pages/article/[id].js:432
501+
#: pages/article/[id].js:413
502502
msgid "Similar messages"
503503
msgstr "相似可疑訊息"
504504

505-
#: pages/article/[id].js:451
505+
#: pages/article/[id].js:432
506506
msgid "No similar messages found"
507507
msgstr "沒有相似的可疑訊息"
508508

@@ -766,15 +766,15 @@ msgstr "目標網站有 HTTPS 錯誤"
766766
msgid "Unknown error"
767767
msgstr "未知錯誤"
768768

769-
#: pages/article/[id].js:401
769+
#: pages/article/[id].js:382
770770
#, javascript-format
771771
msgid "There is ${ replyCount } fact-checking reply to the message"
772772
msgid_plural "There are ${ replyCount } fact-checking replies to the message"
773773
msgstr[0] "本訊息有 ${ replyCount } 則查核回應"
774774
msgstr[1] "本訊息有 ${ replyCount } 則查核回應"
775775

776-
#: pages/article/[id].js:425
777-
#: pages/article/[id].js:461
776+
#: pages/article/[id].js:406
777+
#: pages/article/[id].js:442
778778
msgid "Add Cofacts as friend in LINE"
779779
msgstr "加 LINE 查謠言"
780780

@@ -884,7 +884,7 @@ msgstr "原始碼"
884884
msgid "Contact"
885885
msgstr "聯繫"
886886

887-
#: pages/article/[id].js:416
887+
#: pages/article/[id].js:397
888888
#: pages/reply/[id].js:310
889889
msgid "The content above"
890890
msgstr "以上內容"
@@ -911,37 +911,37 @@ msgstr ""
911911
msgid "Lv.${ user.level } ${ levelName }"
912912
msgstr ""
913913

914-
#: components/ProfilePage/EditProfileDialog.js:52
915-
#: components/ProfilePage/EditProfileDialog.js:69
914+
#: components/ProfilePage/EditProfileDialog.js:57
915+
#: components/ProfilePage/EditProfileDialog.js:74
916916
msgid "Username"
917917
msgstr ""
918918

919-
#: components/ProfilePage/EditProfileDialog.js:57
919+
#: components/ProfilePage/EditProfileDialog.js:62
920920
msgid "Edit profile"
921921
msgstr ""
922922

923-
#: components/ProfilePage/EditProfileDialog.js:61
923+
#: components/ProfilePage/EditProfileDialog.js:66
924924
msgid "Display name"
925925
msgstr ""
926926

927-
#: components/ProfilePage/EditProfileDialog.js:73
927+
#: components/ProfilePage/EditProfileDialog.js:78
928928
#, javascript-format
929929
msgid "Your profile URL will become ${ profileURL }"
930930
msgstr ""
931931

932-
#: components/ProfilePage/EditProfileDialog.js:78
932+
#: components/ProfilePage/EditProfileDialog.js:83
933933
msgid "Bio"
934934
msgstr ""
935935

936-
#: components/ProfilePage/ProfilePage.js:110
936+
#: components/ProfilePage/ProfilePage.js:111
937937
msgid "User not found"
938938
msgstr ""
939939

940-
#: components/ProfilePage/ProfilePage.js:113
940+
#: components/ProfilePage/ProfilePage.js:114
941941
msgid "The user does not exist"
942942
msgstr ""
943943

944-
#: components/ProfilePage/ProfilePage.js:166
944+
#: components/ProfilePage/ProfilePage.js:167
945945
msgid "Replied messages"
946946
msgstr ""
947947

@@ -1043,11 +1043,11 @@ msgid "Creative Commons Attribution-ShareAlike 4.0"
10431043
msgstr "CC授權 姓名標示-相同方式分享 4.0"
10441044

10451045
#: components/AppLayout/AppFooter.js:114
1046-
#: components/AppLayout/LoginModal.js:92
1046+
#: components/AppLayout/LoginModal.js:94
10471047
msgid "User Agreement"
10481048
msgstr ""
10491049

1050-
#: components/AppLayout/LoginModal.js:134
1050+
#: components/AppLayout/LoginModal.js:152
10511051
#, javascript-format
10521052
msgid ""
10531053
"By logging in you agree to ${ termsLink }, and your contribution will be "
@@ -2341,7 +2341,7 @@ msgstr "目前已經存有4萬5千筆以上查證過的資訊,透過投入資
23412341
#: components/ListPageDisplays/ArticleCard.js:104
23422342
#: components/ListPageDisplays/ReplySearchItem.js:110
23432343
#: components/ProfilePage/RepliedArticleTab.js:255
2344-
#: pages/article/[id].js:325
2344+
#: pages/article/[id].js:306
23452345
#: pages/replies.js:255
23462346
msgid "First reported ${ timeAgo }"
23472347
msgstr "首次回報於 ${ timeAgo }"
@@ -2351,6 +2351,15 @@ msgstr "首次回報於 ${ timeAgo }"
23512351
msgid "replied ${ timeAgoStr }"
23522352
msgstr "回應於 ${ timeAgoStr }"
23532353

2354+
#: components/ProfilePage/EditProfileDialog.js:38
2355+
#, javascript-format
2356+
msgid "Changes cannot be saved: ${ error }"
2357+
msgstr ""
2358+
2359+
#: components/Infos/TimeInfo.js:52
2360+
msgid "${ formatted } ago"
2361+
msgstr "${ formatted }前"
2362+
23542363
#: pages/index.js:41
23552364
msgctxt "site title"
23562365
msgid "Cofacts"

0 commit comments

Comments
 (0)