]> Untitled Git - lemmy.git/blob - ui/src/components/moment-time.tsx
Adding support for internationalization / i18n (#189)
[lemmy.git] / ui / src / components / moment-time.tsx
1 import { Component } from 'inferno';
2 import * as moment from 'moment';
3 // import 'moment/locale/de.js';
4 import { getLanguage } from '../utils';
5 import { i18n } from '../i18next';
6
7 interface MomentTimeProps {
8   data: {
9     published?: string;
10     when_?: string;
11     updated?: string;
12   }
13 }
14
15 export class MomentTime extends Component<MomentTimeProps, any> {
16
17   constructor(props: any, context: any) {
18     super(props, context);
19     moment.locale(getLanguage());
20   }
21
22   render() {
23     if (this.props.data.updated) {
24       return (
25         <span title={this.props.data.updated} className="font-italics">{i18n.t('modified')} {moment.utc(this.props.data.updated).fromNow()}</span>
26       )
27     } else {
28       let str = this.props.data.published || this.props.data.when_;
29       return (
30         <span title={str}>{moment.utc(str).fromNow()}</span>
31       )
32     }
33   }
34 }