Skip to content

Commit

Permalink
fix: 🐛 deepl
Browse files Browse the repository at this point in the history
  • Loading branch information
lagleki committed Nov 26, 2023
1 parent 43abe66 commit 2290390
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
build:
docker build -t lojban_made_easy .

rebuild:
docker build --no-cache -t lojban_made_easy .

dev:
docker kill lojban_made_easy 2> /dev/null ; \
docker rm -f lojban_made_easy 2> /dev/null ; \
Expand Down
16 changes: 11 additions & 5 deletions src/lib/korpora/autotranslate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ async function translateText({ text, from, to }) {
],
});
}
const targetDummyDiv = "#target-dummydiv";

const url = `https://deepl.com/es/translator#${from}/${to}/${encodeURIComponent(
text
Expand All @@ -24,9 +23,15 @@ async function translateText({ text, from, to }) {

let translatedText = "\r\n";
let secsPassed = 0;
while (translatedText === "\r\n") {
while (["\r\n", ""].includes(translatedText)) {
if (secsPassed > 120) throw new Error("failed to connect to deepl");
translatedText = await page.textContent(targetDummyDiv);

const targetDummyDiv =
"#headlessui-tabs-panel-7 div.relative.flex.flex-1.flex-col > d-textarea > div > p";
const locator = page.locator(targetDummyDiv);
const firstElement = locator.first();
translatedText = await firstElement.textContent();

await new Promise((resolve) =>
setTimeout(() => {
secsPassed += 0.1;
Expand Down Expand Up @@ -131,6 +136,7 @@ async function autoSplitNTranslate({
);
}

console.log(out);
return out.join("\n");
}

Expand All @@ -139,8 +145,8 @@ module.exports = {
};

// autoSplitNTranslate({
// title: "",
// text: ["hello world"],
// title: "Hello, world!",
// text: ["hello, world!"],
// from: "en",
// to: "ru",
// chunkSize: 8,
Expand Down

0 comments on commit 2290390

Please sign in to comment.