-
Notifications
You must be signed in to change notification settings - Fork 3
/
i18n.js
118 lines (108 loc) · 3.95 KB
/
i18n.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import i18n from "i18next"
import detector from "i18next-browser-languagedetector"
import backend from "i18next-xhr-backend"
import { reactI18nextModule } from "react-i18next"
import indexFR from "./public/locales/fr/index.json"
import indexEN from "./public/locales/en/index.json"
import communityFR from "./public/locales/fr/community.json"
import communityEN from "./public/locales/en/community.json"
import contributeFR from "./public/locales/fr/contribute.json"
import contributeEN from "./public/locales/en/contribute.json"
import cookiesFR from "./public/locales/fr/cookies.json"
import cookiesEN from "./public/locales/en/cookies.json"
import legalFR from "./public/locales/fr/legal.json"
import legalEN from "./public/locales/en/legal.json"
import resourcesFR from "./public/locales/fr/resources.json"
import resourcesEN from "./public/locales/en/resources.json"
import statusFR from "./public/locales/fr/status.json"
import statusEN from "./public/locales/en/status.json"
import showcaseFR from "./public/locales/fr/showcase/index.json"
import showcaseEN from "./public/locales/en/showcase/index.json"
import fastocheFR from "./public/locales/fr/showcase/fastoche.json"
import fastocheEN from "./public/locales/en/showcase/fastoche.json"
import leximpactFR from "./public/locales/fr/showcase/lexImpact.json"
import leximpactEN from "./public/locales/en/showcase/lexImpact.json"
import taxippFR from "./public/locales/fr/showcase/taxIpp.json"
import taxippEN from "./public/locales/en/showcase/taxIpp.json"
import ratesrebatesFR from "./public/locales/fr/showcase/ratesRebates.json"
import ratesrebatesEN from "./public/locales/en/showcase/ratesRebates.json"
import mesaidesFR from "./public/locales/fr/showcase/mesAides.json"
import mesaidesEN from "./public/locales/en/showcase/mesAides.json"
import componentsFR from "./public/locales/fr/components.json"
import componentsEN from "./public/locales/en/components.json"
// the translations
const resources = {
en: {
index: indexEN,
community: communityEN,
contribute: contributeEN,
cookies: cookiesEN,
legal: legalEN,
resources: resourcesEN,
status: statusEN,
showcase: showcaseEN,
fastoche: fastocheEN,
leximpact: leximpactEN,
taxipp: taxippEN,
ratesrebates: ratesrebatesEN,
mesaides: mesaidesEN,
components: componentsEN,
},
fr: {
index: indexFR,
community: communityFR,
contribute: contributeFR,
cookies: cookiesFR,
legal: legalFR,
resources: resourcesFR,
status: statusFR,
showcase: showcaseFR,
fastoche: fastocheFR,
leximpact: leximpactFR,
taxipp: taxippFR,
ratesrebates: ratesrebatesFR,
mesaides: mesaidesFR,
components: componentsFR,
},
}
const switchLanguage = () => (i18n.language == "fr" ? "en" : "fr")
const changeLanguage = (lng) => {
i18n.changeLanguage(lng)
}
const french = () => i18n.language == "fr"
i18n.use(detector)
.use(backend)
.use(reactI18nextModule) // passes i18n down to react-i18next
.init({
ns: [
"index",
"community",
"contribute",
"cookies",
"legal",
"resources",
"status",
"showcase",
"fastoche",
"leximpact",
"mesaides",
"ratesrebates",
"taxipp",
],
defaultNS: "index",
backend: {
// for all available options read the backend's repository readme file
loadPath: "/locales/{{lng}}/{{ns}}.json",
},
resources,
debug: false,
lng: "en",
fallbackLng: "en", // use en if detected lng is not available
keySeparator: true, // we do not use keys in form messages.welcome
interpolation: {
escapeValue: false, // react already safes from xss
},
})
export {
i18n, switchLanguage, changeLanguage, french,
}