Commit e8ddf390 authored by Matija Obreza's avatar Matija Obreza

Merge branch '715-support-different-locales-for-react-time-ago' into 'master'

Support different locales for react-time-ago

Closes #715

See merge request genesys-pgr/genesys-ui!691
parents 674fefb8 5e46928d
......@@ -17,6 +17,7 @@ import { i18nClient } from '../i18n/i18n-client';
import detectLocaleFromPath from '../server/middleware/detectLocaleFromPath';
import getDir from '../server/middleware/detectDirection';
import { receiveLang } from 'actions/applicationConfig';
import TimeAgo from 'javascript-time-ago';
// JSS & MUI
import { MuiThemeProvider } from '@material-ui/core/styles';
......@@ -45,6 +46,8 @@ const SsrI18nProvider = withSSR()(I18nextProvider) as any;
// Configure axios for client
configureBackendApi({ apiUrl: store.getState().applicationConfig.apiUrl || process.env.API_URL || 'http://localhost:8080' });
// Set date's locale for client
import(`javascript-time-ago/locale/${detectedLang}`).then((locale) => TimeAgo.addLocale(locale));
if (__PRELOADED_STATE__ === undefined) {
......
......@@ -14,6 +14,7 @@ import { I18nextProvider } from 'react-i18next';
import thunk from 'redux-thunk';
import rootReducer from 'reducers';
import languages from 'data/Languages';
import TimeAgo from 'javascript-time-ago';
// import { create as createJss } from 'jss';
// import jssPreset from 'jss-preset-default';
......@@ -69,6 +70,7 @@ const prerenderer = (html, errHtml) => (req, res) => {
const locale = detectLocaleFromPath(config.frontendPath, pathname, 0);
// console.log('Detected locale for SSR is', locale);
req.i18n.changeLanguage(locale);
import(`javascript-time-ago/locale/${locale}`).then((timeAgoLocale) => TimeAgo.locale(timeAgoLocale));
}
function renderView() {
......
......@@ -13,10 +13,6 @@ 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);
// 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