Date formatting using locale.

This commit is contained in:
Mike Cao 2020-09-07 19:48:40 -07:00
parent 987fdfd57d
commit ff854150ae
7 changed files with 48 additions and 36 deletions

23
lib/lang.js Normal file
View file

@ -0,0 +1,23 @@
import enMessages from 'lang-compiled/en.json';
import zhCNMessages from 'lang-compiled/zh-CN.json';
import { format } from 'date-fns';
import { enUS, zhCN } from 'date-fns/locale';
export const messages = {
en: enMessages,
'zh-CN': zhCNMessages,
};
export const dateLocales = {
en: enUS,
'zh-CN': zhCN,
};
export const menuOptions = [
{ label: 'English', value: 'en', display: 'EN' },
{ label: '中文 (Chinese Simplified)', value: 'zh-CN', display: '中文' },
];
export function dateFormat(date, str, locale) {
return format(date, str, { locale: dateLocales[locale] || enUS });
}