BIG-71: localize moment date formats.

This commit is contained in:
a.bouhuolia
2021-09-15 11:30:03 +02:00
parent cc13383466
commit d5c1ec58c7
24 changed files with 144 additions and 133 deletions

View File

@@ -5,7 +5,9 @@ import intl from 'react-intl-universal';
import { find } from 'lodash';
import rtlDetect from 'rtl-detect';
import * as R from 'ramda';
import { AppIntlProvider } from './AppIntlProvider';
import withDashboardActions from '../containers/Dashboard/withDashboardActions';
import withDashboard from '../containers/Dashboard/withDashboard';
@@ -56,6 +58,10 @@ function useDocumentDirectionModifier(locale, isRTL) {
}, [isRTL, locale]);
}
function transformMomentLocale(currentLocale) {
return currentLocale === 'ar' ? 'ar-ly' : currentLocale;
}
/**
* Application Intl loader.
*/
@@ -84,7 +90,7 @@ function AppIntlLoader({ appIntlIsLoading, setAppIntlIsLoading, children }) {
});
})
.then(() => {
moment.locale(currentLocale);
moment.locale(transformMomentLocale(currentLocale));
setIsLocalsLoading(false);
});
}, [currentLocale, setIsLocalsLoading]);

View File

@@ -0,0 +1,19 @@
import React from 'react';
import moment from 'moment';
import intl from 'react-intl-universal';
/**
* Format the given date.
*/
export function FormatDate({ value, format = 'YYYY MMM DD' }) {
const localizedFormat = intl.get(`date_format.${format}`);
return moment().format(localizedFormat);
}
/**
* Format date table cell.
*/
export function FormatDateCell({ value, column: { formatDate } }) {
return <FormatDate value={value} {...formatDate} />;
}

View File

@@ -1,3 +1,4 @@
export * from './FormatNumber';
export * from './FormatNumber';
export * from './FormatDate';

View File

@@ -79,6 +79,7 @@ export * from './Drawer';
export * from './Forms';
export * from './MultiSelectTaggable'
export * from './Utils/FormatNumber';
export * from './Utils/FormatDate';
const Hint = FieldHint;