Commit a55b67f6 authored by Oleksii Savran's avatar Oleksii Savran

Support different locales for react-time-ago

parent 56ae3af6
......@@ -3,6 +3,7 @@ import { WithTranslation, withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as _ from 'lodash';
import languages from 'data/Languages';
import { updateHistory } from 'actions/history';
import { loadCrops } from 'crop/actions/public';
......@@ -13,10 +14,12 @@ import { loadIso3Decodings } from 'geo/actions/public';
import { withRouter } from 'react-router-dom';
// FIXME When we start supporting other languages
import TimeAgo from 'javascript-time-ago';
import * as en from 'javascript-time-ago/locale/en';
TimeAgo.locale(en);
languages.forEach(async (lang) => {
const locale = await import(/* webpackMode:"lazy", webpackChunkName: "vendors" */`javascript-time-ago/locale/${lang.short}`);
TimeAgo.addLocale(locale);
});
// required cause of infinite memory leak for chunking and node-12
import(/* webpackMode:"lazy", webpackChunkName: "vendors" */'react-autosuggest');
......
......@@ -7,6 +7,7 @@ import TimeAgo from 'react-time-ago';
export default withTranslation()(function PrettyDate({
value,
t,
i18n,
withoutDay = false,
}: WithTranslation & { value: Date, withoutDay?: boolean }) {
......@@ -18,7 +19,7 @@ export default withTranslation()(function PrettyDate({
return (
<span className="prettydate">
{ diffDays < 4 ?
<TimeAgo date={ valueTime }/>
<TimeAgo date={ valueTime } locale={ i18n.language }/>
:
moment(value).format(withoutDay ? 'MMMM YYYY' : 'D MMMM YYYY')
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment