Skip to content

Commit 7d6e1a1

Browse files
committed
Intl message extraction.
1 parent 9493a73 commit 7d6e1a1

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

lib/ExtractIntlMessages.re

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
11
open Ast_mapper;
22

3-
open Ast_helper;
4-
53
open Asttypes;
64

75
open Parsetree;
86

9-
open Longident;
10-
11-
let isInFormattedMessage = ref(false);
12-
137
let wrapper = argv => {
148
...default_mapper,
15-
label_declaration: (mapper, expr) => {
16-
if (isInFormattedMessage^) {
17-
print_endline(">>> HURRA");
18-
};
19-
print_endline(">>> Label ");
20-
default_mapper.label_declaration(mapper, expr);
21-
},
229
expr: (mapper, expr) =>
2310
switch (expr) {
24-
| {pexp_desc: Pexp_ident({txt, loc}), pexp_attributes: attributes} =>
25-
switch (Longident.flatten(txt)) {
26-
| ["ReactIntl", "FormattedMessage", "make"] =>
27-
print_endline(">>> FormattedMessage");
28-
isInFormattedMessage := true;
29-
| _ => ()
30-
};
31-
if (isInFormattedMessage^) {
32-
print_endline(">>> HURRAAAAAAAAAAAAAAA");
33-
};
34-
let res = default_mapper.expr(mapper, expr);
35-
isInFormattedMessage := false;
36-
res;
11+
| {
12+
pexp_desc:
13+
Pexp_apply(
14+
{pexp_desc: Pexp_ident({txt: Ldot(Ldot(Lident("ReactIntl"), "FormattedMessage"), "make"), loc})},
15+
[
16+
("id", {pexp_desc: Pexp_constant(Const_string(id, _))}),
17+
("defaultMessage", {pexp_desc: Pexp_constant(Const_string(defaultMessage, _))}),
18+
..._,
19+
],
20+
),
21+
} =>
22+
print_endline(id ++ ": " ++ defaultMessage);
23+
default_mapper.expr(mapper, expr);
3724
| expr => default_mapper.expr(mapper, expr)
3825
},
3926
};

0 commit comments

Comments
 (0)