File tree Expand file tree Collapse file tree 4 files changed +418
-343
lines changed Expand file tree Collapse file tree 4 files changed +418
-343
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,36 @@ let reducer = (_, action) =>
8
8
| SetLocale (locale ) => locale
9
9
};
10
10
11
+ // As an alternative to using IntlProvider like in the main make function below,
12
+ // you can construct the intl instance yourself and pass it to RawIntlProvider instead.
13
+ // This is especially useful if you need to create/use the intl instance outside of a
14
+ // React component.
15
+ module WithRawIntlProvider = {
16
+ let createIntlForLocale = locale => {
17
+ let intlConfig =
18
+ ReactIntl . intlConfig(
19
+ ~locale= locale-> Locale . toString,
20
+ ~messages= locale-> Locale . translations-> Util . translationsToDict,
21
+ () ,
22
+ );
23
+ let intlCache = ReactIntl . createIntlCache() ;
24
+
25
+ ReactIntl . createIntl(intlConfig, intlCache);
26
+ };
27
+
28
+ [@ react . component ]
29
+ let make = () => {
30
+ let (locale , dispatch ) = reducer-> React . useReducer(initialState);
31
+
32
+ let intl =
33
+ React . useMemo1(() => createIntlForLocale(locale), [| locale|] );
34
+
35
+ <ReactIntl . RawIntlProvider value= intl>
36
+ <Page locale setLocale= {locale => locale-> SetLocale -> dispatch} />
37
+ </ReactIntl . RawIntlProvider >;
38
+ };
39
+ };
40
+
11
41
[@ react . component ]
12
42
let make = () => {
13
43
let (locale , dispatch ) = reducer-> React . useReducer(initialState);
Original file line number Diff line number Diff line change 22
22
"reason-react" : " >=0.7.0"
23
23
},
24
24
"devDependencies" : {
25
- "bs-platform" : " 5.0.6 " ,
25
+ "bs-platform" : " 5.2.1 " ,
26
26
"bs-react-intl-extractor-bin" : " 0.7.0" ,
27
27
"bsb-js" : " ^1.1.7" ,
28
- "parcel-bundler" : " 1.12.3 " ,
28
+ "parcel-bundler" : " 1.12.4 " ,
29
29
"react" : " 16.8.6" ,
30
30
"react-dom" : " 16.8.6" ,
31
- "react-intl" : " 3.1.6 " ,
31
+ "react-intl" : " 3.4.0 " ,
32
32
"reason-react" : " 0.7.0"
33
33
},
34
34
"repository" : {
Original file line number Diff line number Diff line change @@ -140,6 +140,38 @@ external domTag: string => textComponent = "%identity";
140
140
external textComponent : React . component (' props ) => textComponent =
141
141
"% identity " ;
142
142
143
+ type intlCache ;
144
+
145
+ [@ bs . module "react-intl" ]
146
+ external createIntlCache : unit => intlCache = "createIntlCache" ;
147
+
148
+ type intlConfig ;
149
+
150
+ [@ bs . obj ]
151
+ external intlConfig :
152
+ (
153
+ ~locale : string ,
154
+ ~timeZone : string =?,
155
+ ~formats : Js . t ({..})=?, /* TODO */
156
+ ~textComponent : textComponent =?,
157
+ ~messages : Js . Dict . t (string ),
158
+ ~defaultLocale : string =?,
159
+ ~defaultFormats : Js . t ({..})=?, /* TODO */
160
+ ~onError : string => unit =?,
161
+ unit
162
+ ) =>
163
+ intlConfig =
164
+ "" ;
165
+
166
+ [@ bs . module "react-intl" ]
167
+ external createIntl : (intlConfig , intlCache ) => Intl . t = "createIntl" ;
168
+
169
+ module RawIntlProvider = {
170
+ [@ react . component ] [@ bs . module "react-intl" ]
171
+ external make : (~value : Intl . t , ~children : React . element ) => React . element =
172
+ "RawIntlProvider" ;
173
+ };
174
+
143
175
module IntlProvider = {
144
176
[@ react . component ] [@ bs . module "react-intl" ]
145
177
external make :
You can’t perform that action at this time.
0 commit comments