-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathApp.res
46 lines (37 loc) · 1.4 KB
/
App.res
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
type action = SetLocale(Locale.locale)
let initialState = Locale.En
let reducer = (_, action) =>
switch action {
| SetLocale(locale) => locale
}
// As an alternative to using IntlProvider like in the main make function below,
// you can construct the intl instance yourself and pass it to RawIntlProvider instead.
// This is especially useful if you need to create/use the intl instance outside of a
// React component.
module WithRawIntlProvider = {
let createIntlForLocale = locale => {
let intlConfig = ReactIntl.intlConfig(
~locale=locale->Locale.toString,
~messages=locale->Locale.translations->Translation.toDict,
(),
)
let intlCache = ReactIntl.createIntlCache()
ReactIntl.createIntl(intlConfig, intlCache)
}
@react.component
let make = () => {
let (locale, dispatch) = reducer->React.useReducer(initialState)
let intl = React.useMemo1(() => createIntlForLocale(locale), [locale])
<ReactIntl.RawIntlProvider value=intl>
<Page locale setLocale={locale => locale->SetLocale->dispatch} />
</ReactIntl.RawIntlProvider>
}
}
@react.component
let make = () => {
let (locale, dispatch) = reducer->React.useReducer(initialState)
<ReactIntl.IntlProvider
locale={locale->Locale.toString} messages={locale->Locale.translations->Translation.toDict}>
<Page locale setLocale={locale => locale->SetLocale->dispatch} />
</ReactIntl.IntlProvider>
}