File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import i18n from 'i18next';
2
2
import { initReactI18next } from 'react-i18next' ;
3
3
import LanguageDetector from 'i18next-browser-languagedetector' ;
4
4
import Backend from 'i18next-http-backend' ;
5
+ import { enUS , es } from 'date-fns/locale' ;
5
6
6
7
const fallbackLng = [ 'en-US' ] ;
7
8
const availableLanguages = [ 'en-US' , 'es-419' ] ;
@@ -14,6 +15,18 @@ export function languageKeyToLabel(lang) {
14
15
return languageMap [ lang ] ;
15
16
}
16
17
18
+ export function languageKeyToDateLocale ( lang ) {
19
+ const languageMap = {
20
+ 'en-US' : enUS ,
21
+ 'es-419' : es
22
+ } ;
23
+ return languageMap [ lang ] ;
24
+ }
25
+
26
+ export function currentDateLocale ( ) {
27
+ return languageKeyToDateLocale ( i18n . language ) ;
28
+ }
29
+
17
30
const options = {
18
31
loadPath : '/locales/{{lng}}/translations.json' ,
19
32
requestOptions : { // used for fetch, can also be a function (payload) => ({ method: 'GET' })
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import isValid from 'date-fns/isValid';
5
5
import parseISO from 'date-fns/parseISO' ;
6
6
import i18next from 'i18next' ;
7
7
8
+ import { currentDateLocale } from '../i18n' ;
9
+
8
10
function parse ( maybeDate ) {
9
11
const date = maybeDate instanceof Date ? maybeDate : parseISO ( maybeDate ) ;
10
12
@@ -34,7 +36,8 @@ export default {
34
36
}
35
37
36
38
const timeAgo = formatDistanceToNow ( parsed , {
37
- includeSeconds : false
39
+ includeSeconds : false ,
40
+ locale : currentDateLocale ( )
38
41
} ) ;
39
42
return i18next . t ( 'formatDate.Ago' , { timeAgo } ) ;
40
43
}
@@ -46,7 +49,7 @@ export default {
46
49
const formatType = showTime ? 'PPpp' : 'PP' ;
47
50
48
51
if ( parsed ) {
49
- return format ( parsed , formatType ) ;
52
+ return format ( parsed , formatType , { locale : currentDateLocale ( ) } ) ;
50
53
}
51
54
52
55
return '' ;
You can’t perform that action at this time.
0 commit comments