Skip to content

Unescape extracted strings #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let fromStringMap ?description map =
| _ -> None

let toJson {id; defaultMessage; description} : Yojson.Basic.t =
let defaultMessage = Scanf.unescaped defaultMessage in
match description with
| Some description ->
`Assoc
Expand Down
15 changes: 15 additions & 0 deletions test/Test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ let testExtractIntlPpx () =
}
]|}

let testExtractEscaped () =
testExtract ["testData/testEscape"]
{|[
{
"id": "ReScript.decodeError",
"defaultMessage":
"The configuration could not be decoded.\n\nPlease contact your administrator."
},
{
"id": "ReScript.trackingActive",
"defaultMessage": "Tracking active in \"{incident}\""
}
]|}

let testPathNotFoundError () =
Alcotest.check_raises "dir not found"
(Extractor.PathNotFound "testData/someDir") (fun () ->
Expand Down Expand Up @@ -181,6 +195,7 @@ let testSetExtract =
test_case "Extract full" `Quick testExtractFull;
test_case "Extract partial" `Quick testExtractPartial;
test_case "Extract ReScript" `Quick testExtractReScript;
test_case "Extract messages with escape chars" `Quick testExtractEscaped;
test_case "Extract Intl PPX" `Quick testExtractIntlPpx;
test_case "Path not found" `Quick testPathNotFoundError;
]
Expand Down
10 changes: 10 additions & 0 deletions test/testData/testEscape/Test_Escape.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<FormattedMessage
id="ReScript.decodeError"
defaultMessage="The configuration could not be decoded.\n\nPlease contact your administrator."
/>

<FormattedMessage
id="ReScript.trackingActive"
defaultMessage="Tracking active in \"{incident}\""
values={"incident": "42"}
/>