Skip to content

Commit 0315db4

Browse files
fix: always use English for TimeAgo (#894)
* fix: always use English for TimeAgo * apply suggestions
1 parent f85c389 commit 0315db4

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

ui/src/common/LastUsedCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Typography} from '@mui/material';
22
import React from 'react';
33
import TimeAgo from 'react-timeago';
4+
import {TimeAgoFormatter} from './TimeAgoFormatter';
45

56
export const LastUsedCell: React.FC<{lastUsed: string | null}> = ({lastUsed}) => {
67
if (lastUsed === null) {
@@ -11,5 +12,5 @@ export const LastUsedCell: React.FC<{lastUsed: string | null}> = ({lastUsed}) =>
1112
return <Typography title={lastUsed}>Recently</Typography>;
1213
}
1314

14-
return <TimeAgo date={lastUsed} />;
15+
return <TimeAgo date={lastUsed} formatter={TimeAgoFormatter.long} />;
1516
};

ui/src/common/TimeAgoFormatter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {Formatter} from 'react-timeago';
2+
import {makeIntlFormatter} from 'react-timeago/defaultFormatter';
3+
4+
export const TimeAgoFormatter: Record<'long' | 'narrow', Formatter> = {
5+
long: makeIntlFormatter({style: 'long', locale: 'en'}),
6+
narrow: makeIntlFormatter({style: 'narrow', locale: 'en'}),
7+
};

ui/src/message/Message.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {Markdown} from '../common/Markdown';
1111
import * as config from '../config';
1212
import {IMessageExtras} from '../types';
1313
import {contentType, RenderMode} from './extras';
14-
import {makeIntlFormatter} from 'react-timeago/defaultFormatter';
14+
import {TimeAgoFormatter} from '../common/TimeAgoFormatter';
1515

1616
const PREVIEW_LENGTH = 500;
1717

@@ -248,7 +248,7 @@ const HeaderWide = ({
248248
</Typography>
249249
</div>
250250
<Typography variant="body1" className={classes.date}>
251-
<TimeAgo date={date} formatter={makeIntlFormatter({style: 'narrow'})} />
251+
<TimeAgo date={date} formatter={TimeAgoFormatter.narrow} />
252252
</Typography>
253253
<IconButton
254254
onClick={fDelete}
@@ -279,7 +279,7 @@ const HeaderSmall = ({
279279
{appName}
280280
</Typography>
281281
<Typography variant="body1" className={classes.date}>
282-
<TimeAgo date={date} formatter={makeIntlFormatter({style: 'long'})} />
282+
<TimeAgo date={date} formatter={TimeAgoFormatter.long} />
283283
</Typography>
284284
</div>
285285
<div style={{display: 'flex', alignItems: 'end', flexDirection: 'column'}}>

ui/src/typedef/react-timeago.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ declare module 'react-timeago' {
33

44
export type FormatterOptions = {
55
style?: 'long' | 'short' | 'narrow';
6+
locale?: string;
67
};
78
export type Formatter = (options: FormatterOptions) => React.ReactNode;
89

0 commit comments

Comments
 (0)