1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
import { MetaKind } from '@ts/types/app';
import { useRouter } from 'next/router';
import { useIntl } from 'react-intl';
import { MetaItem } from '..';
const ReadingTime = ({
time,
words,
kind,
}: {
time: number;
words: number;
kind: MetaKind;
}) => {
const intl = useIntl();
const { locale } = useRouter();
const getEstimation = () => {
if (time < 0) {
return intl.formatMessage({
defaultMessage: 'less than 1 minute',
description: 'ReadingTime: Reading time value',
});
}
return intl.formatMessage(
{
defaultMessage:
'{time, plural, =0 {# minutes} one {# minute} other {# minutes}}',
description: 'ReadingTime: reading time value',
},
{ time }
);
};
return (
<MetaItem
title={intl.formatMessage({
defaultMessage: 'Reading time:',
description: 'ReadingTime: reading time meta label',
})}
value={getEstimation()}
info={intl.formatMessage(
{
defaultMessage: `Approximately {number} words`,
description: 'ReadingTime: number of words',
},
{ number: words.toLocaleString(locale) }
)}
kind={kind}
/>
);
};
export default ReadingTime;
|