Skip to content
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
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/04-variables/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,4 @@ We kunnen variabelen declareren om gegevens op te slaan door gebruik te maken va
- `var` -- is een ouderwetse variabele declaratie. Normaal gesproken gebruiken we het helemaal niet, maar we behandelen subtiele verschillen met `let` in het hoofdstuk <info:var>, voor het geval je ze nodig hebt.
- `const` -- is als `let`, maar de waarde van de variabele kan niet worden veranderd.

Variabelen moeten worden benoemd op een manier die ons in staat stelt om gemakkelijk te begrijpen wat er in zit.
Variabelen moeten worden benoemd op een manier die ons in staat stelt om gemakkelijk te begrijpen wat er in zit.
1 change: 1 addition & 0 deletions filesToTranslate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files": ["./nl.javascript.info/1-js/02-first-steps/04-variables/1-hello-variables/solution.md", "./nl.javascript.info/1-js/02-first-steps/04-variables/1-hello-variables/task.md", "./nl.javascript.info/1-js/02-first-steps/04-variables/2-declare-variables/solution.md", "./nl.javascript.info/1-js/02-first-steps/04-variables/2-declare-variables/task.md", "./nl.javascript.info/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md", "./nl.javascript.info/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md", "./nl.javascript.info/1-js/02-first-steps/04-variables/article.md"]}
50 changes: 50 additions & 0 deletions translateScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const json = require('./filesToTranslate.json');
fs = require('fs');

global.fetch = require("node-fetch");
const puppeteer = require('puppeteer');

async function translate(incomingText) {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://www.deepl.com/translator', {waitUntil: 'domcontentloaded'});

await page.evaluate(() => { localStorage.setItem('LMT_preferredLangs', 'EN,NL'); });
await page.evaluate(() => { localStorage.setItem('LMT_preferredLangVariants', 'en-US'); });
await page.evaluate(() => { localStorage.setItem('LMT_selectedTargetLang', 'NL'); });

await page.waitForSelector('.dl_cookieBanner--buttonAll');
await page.click('.dl_cookieBanner--buttonAll');
await page.evaluate(val => document.querySelector('.lmt__source_textarea').value = val, incomingText);
await page.click('.lmt__language_select--target');
await page.evaluate(() => {
[...document.querySelectorAll('.lmt__language_select__menu button')].find(element => element.textContent === 'Dutch').click();
});
await page.waitFor(5000);
let translatedText = await page.$eval('.lmt__target_textarea', el => el.value);
await browser.close();
return [incomingText, translatedText];
}

function startTranslating(url, file){
fetch(url)
.then(response => response.text())
.then(response => translate(response))
.then(response => {
fs.writeFile(file, `${response[0]}\n====================\n${response[1]}`, function (err) {
if (err) return console.log("schrijven mislukt! " + err);
console.log('schrijven gelukt');
});
})
.catch(err => console.log(err));
}

function fetchJSON(){
let files = json.files;
files.forEach(el => {
//console.log();
startTranslating("https://raw.githubusercontent.com/javascript-tutorial/nl.javascript.info/master/"+el.slice(21, el.length), "." + el.slice(20, el.length))
});
}

fetchJSON();