Skip to content

Commit 45d0e0a

Browse files
authored
Unescape extracted strings (#83)
1 parent 2c17388 commit 45d0e0a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/Message.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let fromStringMap ?description map =
1414
| _ -> None
1515

1616
let toJson {id; defaultMessage; description} : Yojson.Basic.t =
17+
let defaultMessage = Scanf.unescaped defaultMessage in
1718
match description with
1819
| Some description ->
1920
`Assoc

test/Test.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ let testExtractIntlPpx () =
145145
}
146146
]|}
147147

148+
let testExtractEscaped () =
149+
testExtract ["testData/testEscape"]
150+
{|[
151+
{
152+
"id": "ReScript.decodeError",
153+
"defaultMessage":
154+
"The configuration could not be decoded.\n\nPlease contact your administrator."
155+
},
156+
{
157+
"id": "ReScript.trackingActive",
158+
"defaultMessage": "Tracking active in \"{incident}\""
159+
}
160+
]|}
161+
148162
let testPathNotFoundError () =
149163
Alcotest.check_raises "dir not found"
150164
(Extractor.PathNotFound "testData/someDir") (fun () ->
@@ -181,6 +195,7 @@ let testSetExtract =
181195
test_case "Extract full" `Quick testExtractFull;
182196
test_case "Extract partial" `Quick testExtractPartial;
183197
test_case "Extract ReScript" `Quick testExtractReScript;
198+
test_case "Extract messages with escape chars" `Quick testExtractEscaped;
184199
test_case "Extract Intl PPX" `Quick testExtractIntlPpx;
185200
test_case "Path not found" `Quick testPathNotFoundError;
186201
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<FormattedMessage
2+
id="ReScript.decodeError"
3+
defaultMessage="The configuration could not be decoded.\n\nPlease contact your administrator."
4+
/>
5+
6+
<FormattedMessage
7+
id="ReScript.trackingActive"
8+
defaultMessage="Tracking active in \"{incident}\""
9+
values={"incident": "42"}
10+
/>

0 commit comments

Comments
 (0)