File tree 8 files changed +38
-49
lines changed
8 files changed +38
-49
lines changed Original file line number Diff line number Diff line change 11
11
- Removed ` Intl.now `
12
12
- ` FormattedRelative ` has been renamed to ` FormattedRelativeTime ` and its API has been changed as well
13
13
- ` Intl.formatRelative ` has been renamed to ` Intl.formatRelativeTime ` and its API has been changed as well
14
+ * ** [ BREAKING ] ** Changed ` ReactIntl.message ` to record type.
15
+ * ** [ BREAKING ] ** Removed ` ReactIntl.translation ` .
14
16
* ** [ BREAKING ] ** Removed ` ReactIntlCompat ` .
15
17
16
18
# 1.1.0
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ module WithRawIntlProvider = {
17
17
let intlConfig =
18
18
ReactIntl . intlConfig(
19
19
~locale= locale-> Locale . toString,
20
- ~messages= locale-> Locale . translations-> Util . translationsToDict ,
20
+ ~messages= locale-> Locale . translations-> Translation . toDict ,
21
21
() ,
22
22
);
23
23
let intlCache = ReactIntl . createIntlCache() ;
@@ -44,7 +44,7 @@ let make = () => {
44
44
45
45
<ReactIntl . IntlProvider
46
46
locale= {locale-> Locale . toString}
47
- messages= {locale-> Locale . translations-> Util . translationsToDict }>
47
+ messages= {locale-> Locale . translations-> Translation . toDict }>
48
48
<Page locale setLocale= {locale => locale-> SetLocale -> dispatch} />
49
49
</ReactIntl . IntlProvider >;
50
50
};
Original file line number Diff line number Diff line change 1
1
[@ bs . module "./translations/en.json" ]
2
- external en : array (ReactIntl . translation ) = "default" ;
2
+ external en : array (Translation . t ) = "default" ;
3
3
[@ bs . module "./translations/ru.json" ]
4
- external ru : array (ReactIntl . translation ) = "default" ;
4
+ external ru : array (Translation . t ) = "default" ;
5
5
6
6
type locale =
7
7
| En
Original file line number Diff line number Diff line change 1
1
open ReactIntl ;
2
- open PageLocale ;
3
2
4
3
[@ react . component ]
5
4
let make = (~locale, ~setLocale) => {
@@ -23,12 +22,12 @@ let make = (~locale, ~setLocale) => {
23
22
<FormattedMessage id= "page.world" defaultMessage= "World" />
24
23
</div >
25
24
<div >
26
- {intl-> Intl . formatMessage(pageLocale ## today)-> React . string}
25
+ {intl-> Intl . formatMessage(PageLocale . today)-> React . string}
27
26
" " -> React . string
28
27
{intl-> Intl . formatDate(Js . Date . make() )-> React . string}
29
28
" (intl.formatDate)" -> React . string
30
29
<br />
31
- {intl-> Intl . formatMessage(pageLocale ## today)-> React . string}
30
+ {intl-> Intl . formatMessage(PageLocale . today)-> React . string}
32
31
" " -> React . string
33
32
<FormattedDate value= {Js . Date . make() } />
34
33
" (FormattedDate)" -> React . string
Original file line number Diff line number Diff line change 1
- let pageLocale =
2
- [@ intl . messages ]
3
- {
4
- "hello" : {
5
- "id" : "page.hello" ,
6
- "defaultMessage" : "Hello" ,
7
- },
8
- "world" : {
9
- "id" : "page.world" ,
10
- "defaultMessage" : "World" ,
11
- },
12
- "today" : {
13
- "id" : "page.today" ,
14
- "defaultMessage" : "Today is" ,
15
- },
16
- };
1
+ open ReactIntl ;
2
+ [@ intl . messages ];
3
+
4
+ let hello = {id: "page.hello" , defaultMessage: "Hello" };
5
+ let world = {id: "page.world" , defaultMessage: "World" };
6
+ let today = {id: "page.today" , defaultMessage: "Today is" };
Original file line number Diff line number Diff line change
1
+ type t = {
2
+ id: string ,
3
+ defaultMessage: string ,
4
+ message: Js . nullable (string ),
5
+ };
6
+
7
+ let toDict = (translations: array (t )) => {
8
+ translations-> Belt . Array . reduce(
9
+ Js . Dict . empty() ,
10
+ (dict, entry) => {
11
+ dict-> Js . Dict . set(
12
+ entry. id,
13
+ switch (entry. message-> Js . Nullable . toOption) {
14
+ | None
15
+ | Some ("" ) => entry. defaultMessage
16
+ | Some (message ) => message
17
+ },
18
+ );
19
+ dict;
20
+ },
21
+ );
22
+ };
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -90,16 +90,8 @@ external displayNameFormatOptions:
90
90
displayNameFormatOptions ;
91
91
92
92
type message = {
93
- .
94
- "id": string ,
95
- "defaultMessage": string ,
96
- };
97
-
98
- type translation = {
99
- .
100
- "id": string ,
101
- "defaultMessage": string ,
102
- "message": Js . nullable (string ),
93
+ id: string ,
94
+ defaultMessage: string ,
103
95
};
104
96
105
97
type part = {
You can’t perform that action at this time.
0 commit comments