-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.ts
54 lines (44 loc) · 1.16 KB
/
i18n.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import FRTranslation from './assets/locales/fr.json'
import ENTranslation from './assets/locales/en.json'
import { setDefaultOptions, format as formatDate } from 'date-fns'
import { enUS, fr } from 'date-fns/locale'
const dateFnsLocales = {
en: enUS,
fr
}
i18n.on('languageChange', (lng: string) => {
setDefaultOptions({ locale: dateFnsLocales[lng] })
})
setDefaultOptions({ locale: dateFnsLocales.en })
const resources = {
en: {
translation: ENTranslation
},
fr: {
translation: FRTranslation
}
}
i18n
.use(initReactI18next)
.init({
lng: 'en',
fallbackLng: ['en', 'fr'],
debug: false,
resources,
returnObjects: true,
interpolation: {
escapeValue: false
}
})
i18n.services.formatter.add('uppercase', (value: string) => {
return value.toUpperCase()
})
i18n.services.formatter.add('capitalise', (value: string) => {
return value.charAt(0).toUpperCase() + value.substring(1)
})
i18n.services.formatter.add('translateDate', (value: Date, _, options: { format: string}) => {
return formatDate(value, options.format)
})
export default i18n