Skip to content

Commit

Permalink
Fixed multiple sentences in Google
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscop committed Nov 8, 2021
1 parent c1b4c1f commit c607150
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/engines/google.js
Expand Up @@ -6,7 +6,7 @@ export default {
],
parse: res =>
res.json().then(body => {
body = body && body[0] && body[0][0] && body[0][0][0];
body = body && body[0] && body[0][0] && body[0].map(s => s[0]).join("");
if (!body) throw new Error("Translation not found");
return body;
})
Expand Down
11 changes: 11 additions & 0 deletions src/engines/google.test.js
Expand Up @@ -47,4 +47,15 @@ describe("google full requests", () => {
const opts = { to: "es", engine: "google" };
expect(await translate("Hello world", opts)).toMatch(/Hola mundo/i);
});

it("works with punctuation", async () => {
const opts = { to: "pt", engine: "google" };
const text = await translate(
"What do you call a pig that knows karate? A pork chop!",
opts
);
expect(text).toBe(
"Como você chama um porco que sabe caratê? Costeleta de porco!"
);
});
});

0 comments on commit c607150

Please sign in to comment.