From 59d3b0f0fbae111a0b611a75452c3123a273b935 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 09:06:06 +0000 Subject: [PATCH 01/20] move "gowebcam" enabled styles over to css --- main.css | 5 +++++ main.js | 15 --------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/main.css b/main.css index 3a74985..0c271a5 100644 --- a/main.css +++ b/main.css @@ -753,6 +753,11 @@ body { margin: 20px; padding: 10px 50px; } +.gowebcam:enabled { + background-color: #3C3; + color: black; + font-weight: bold; +} .mainmenuclass { display: inherit; diff --git a/main.js b/main.js index 155ad38..ea4f9ec 100644 --- a/main.js +++ b/main.js @@ -7651,9 +7651,6 @@ async function grabVideo(quality = 0, eleName = 'previewWebcam', selector = "sel if (gowebcam) { gowebcam.disabled = false; gowebcam.dataset.ready = "true"; - gowebcam.style.backgroundColor = "#3C3"; - gowebcam.style.color = "black"; - gowebcam.style.fontWeight = "bold"; gowebcam.innerHTML = "START"; miniTranslate(gowebcam, "start"); } @@ -7845,9 +7842,6 @@ async function grabVideo(quality = 0, eleName = 'previewWebcam', selector = "sel if (gowebcam) { gowebcam.disabled = false; gowebcam.dataset.ready = "true"; - gowebcam.style.backgroundColor = "#3C3"; - gowebcam.style.color = "black"; - gowebcam.style.fontWeight = "bold"; gowebcam.innerHTML = "START"; miniTranslate(gowebcam, "start"); } @@ -8111,9 +8105,6 @@ async function grabAudio(eleName = "previewWebcam", selector = "#audioSource", t if (gowebcam) { gowebcam.disabled = false; gowebcam.dataset.ready = "true"; - gowebcam.style.backgroundColor = "#3C3"; - gowebcam.style.color = "black"; - gowebcam.style.fontWeight = "bold"; gowebcam.innerHTML = "START"; miniTranslate(gowebcam, "start"); } @@ -9867,9 +9858,6 @@ function setupWebcamSelection(stream = null) { if (gowebcam) { gowebcam.disabled = false; gowebcam.dataset.ready = "true"; - gowebcam.style.backgroundColor = "#3C3"; - gowebcam.style.color = "black"; - gowebcam.style.fontWeight = "bold"; gowebcam.innerHTML = "START"; miniTranslate(gowebcam, "start"); } @@ -10068,9 +10056,6 @@ function previewWebcam() { gowebcam.style.display = ""; gowebcam.disabled = false; gowebcam.dataset.ready = "true"; - gowebcam.style.backgroundColor = "#3C3"; - gowebcam.style.color = "black"; - gowebcam.style.fontWeight = "bold"; gowebcam.innerHTML = "START"; miniTranslate(gowebcam, "start"); } From ab1b0f2aa0706f13402af5e0452db1bfa61fd9fa Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:38:49 +0000 Subject: [PATCH 02/20] Create ci-generateTranslations.js --- ci-generateTranslations.js | 167 +++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 ci-generateTranslations.js diff --git a/ci-generateTranslations.js b/ci-generateTranslations.js new file mode 100644 index 0000000..e3dc087 --- /dev/null +++ b/ci-generateTranslations.js @@ -0,0 +1,167 @@ +var https = require("https"); +const jsdom = require("jsdom"); +const { JSDOM } = jsdom; +const axios = require("axios").default; +const fs = require("fs"); + +const dom = new JSDOM(``, { + url: "https://obs.ninja", + contentType: "text/html", + includeNodeLocations: true, + storageQuota: 10000000, + pretendToBeVisual: true, +}); + +global.document = new JSDOM(``, { + url: "https://obs.ninja", + contentType: "text/html", + includeNodeLocations: true, + storageQuota: 10000000, + pretendToBeVisual: false, +}).window.document; + +function downloadTranslation(filename, trans = {}) { + // downloads the current translation to a file + console.log("Saving translation: " + filename); + const textDoc = JSON.stringify(trans, null, 2); + + fs.writeFile(`translations\\${filename}.json`, textDoc, function (err) { + if (err) { + return console.log(err); + } + console.log("The file was saved!"); + }); + + return trans; +} + +async function updateTranslation(filename) { + // updates the website with a specific translation + let data = await axios({ + method: "get", + url: `https://obs.ninja/translations/${filename}.json?${( + Math.random() * 100 + ).toString()}`, + }).then(function (response) { + return response.data; + }); + + const oldTransItems = data["innerHTML"]; + + // const allItems1 = document.querySelectorAll('[data-translate]'); + + allItems.forEach((ele) => { + const key = ele.dataset.translate; //.replace(/[\W]+/g, "-").toLowerCase(); + if (key in oldTransItems) { + ele.innerHTML = oldTransItems[key]; + } + }); + + const oldTransTitles = data["titles"]; + //const allTitles1 = document.querySelectorAll('[title]'); + allTitles.forEach((ele) => { + const key = ele.dataset.key; + //const key = ele.title.replace(/[\W]+/g, "-").toLowerCase(); + if (key in oldTransTitles) { + ele.title = oldTransTitles[key]; + } + }); + + const oldTransPlaceholders = data.placeholders; + //const allPlaceholders1 = document.querySelectorAll('[placeholder]'); + allPlaceholders.forEach((ele) => { + const key = ele.dataset.key; + //const key = ele.placeholder.replace(/[\W]+/g, "-").toLowerCase(); + if (key in oldTransPlaceholders) { + ele.placeholder = oldTransPlaceholders[key]; + } + }); + + return [true, data]; +} + +const updateList = [ + "cs", + "de", + "en", + "es", + "fr", + "it", + "ja", + "nl", + "pig", + "pt", + "ru", + "tr", + "blank", +]; // list of languages to update. Update this if you add a new language. + +const allItems = document.querySelectorAll("[data-translate]"); +const defaultTrans = {}; +allItems.forEach((ele) => { + const key = ele.dataset.translate; //.replace(/[\W]+/g, "-").toLowerCase(); + defaultTrans[key] = ele.innerHTML; +}); + +const defaultTransTitles = {}; +const allTitles = document.querySelectorAll("[title]"); +allTitles.forEach((ele) => { + const key = ele.title.replace(/[\W]+/g, "-").toLowerCase(); + ele.dataset.key = key; + defaultTransTitles[key] = ele.title; +}); + +const defaultTransPlaceholders = {}; +const allPlaceholders = document.querySelectorAll("[placeholder]"); +allPlaceholders.forEach((ele) => { + const key = ele.placeholder.replace(/[\W]+/g, "-").toLowerCase(); + ele.dataset.key = key; + defaultTransPlaceholders[key] = ele.placeholder; +}); + +const combinedTrans = {}; +combinedTrans.titles = defaultTransTitles; +combinedTrans.innerHTML = defaultTrans; +combinedTrans.placeholders = defaultTransPlaceholders; + +var counter = 0; +for (const i in updateList) { + const lang = updateList[i]; + setTimeout( + (ln) => { + var suceess = updateTranslation(ln); // we don't need to worry about DATA. + updateTranslation(ln).then(function (suceess) { + const newTrans = suceess[1]["innerHTML"]; + //const allItems = document.querySelectorAll('[data-translate]'); + allItems.forEach((ele) => { + const key = ele.dataset.translate; //.replace(/[\W]+/g, "-").toLowerCase(); + newTrans[key] = ele.innerHTML; + }); + + const newTransTitles = suceess[1]["titles"]; + //const allTitles = document.querySelectorAll('[title]'); + allTitles.forEach((ele) => { + const key = ele.dataset.key; + newTransTitles[key] = ele.title; + }); + + const newPlaceholders = suceess[1]["placeholders"]; + // const allPlaceholders = document.querySelectorAll('[placeholder]'); + allPlaceholders.forEach((ele) => { + const key = ele.dataset.key; + newPlaceholders[key] = ele.placeholder; + }); + + // //// DOWNLOAD UPDATED TRANSLATION + const outputTrans = {}; + outputTrans["titles"] = newTransTitles; + outputTrans["innerHTML"] = newTrans; + outputTrans["placeholders"] = newPlaceholders; + downloadTranslation(ln, outputTrans); + }); + }, + counter, + lang + ); + counter += 800; +} From e91d972753dac5af062f658065e7629888b845cf Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:45:14 +0000 Subject: [PATCH 03/20] Create main.yml --- .github/workflows/main.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1f863b7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +# This is a basic workflow to help you get started with Actions + +name: Generate translations + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the master branch + #push: + # branches: [ master ] + #pull_request: + # branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + - run: node .github/ci-generateTranslations.js + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + From c7bb3f8acf84aeb4822bb75016366d288419a87c Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:45:32 +0000 Subject: [PATCH 04/20] move script --- .../ci-generateTranslations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ci-generateTranslations.js => .github/ci-generateTranslations.js (98%) diff --git a/ci-generateTranslations.js b/.github/ci-generateTranslations.js similarity index 98% rename from ci-generateTranslations.js rename to .github/ci-generateTranslations.js index e3dc087..b51fa1c 100644 --- a/ci-generateTranslations.js +++ b/.github/ci-generateTranslations.js @@ -25,7 +25,7 @@ function downloadTranslation(filename, trans = {}) { console.log("Saving translation: " + filename); const textDoc = JSON.stringify(trans, null, 2); - fs.writeFile(`translations\\${filename}.json`, textDoc, function (err) { + fs.writeFile(`..\\translations\\${filename}.json`, textDoc, function (err) { if (err) { return console.log(err); } From fc488141115daa400f70f4048f99f3cd58d924e7 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:48:24 +0000 Subject: [PATCH 05/20] Create requirements.txt --- .github/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/requirements.txt diff --git a/.github/requirements.txt b/.github/requirements.txt new file mode 100644 index 0000000..cef8ef7 --- /dev/null +++ b/.github/requirements.txt @@ -0,0 +1,2 @@ +jsdom +axios \ No newline at end of file From d1a2cc89f58d1f3b98959cbabfc4f807c4296cff Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:48:34 +0000 Subject: [PATCH 06/20] Update main.yml --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1f863b7..978239d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,6 +26,7 @@ jobs: - uses: actions/setup-node@v2 with: node-version: '14' + - run: pip install -r .github/requirements.txt - run: node .github/ci-generateTranslations.js - name: Create Pull Request uses: peter-evans/create-pull-request@v3 From a09d86d79ee2977dc9810f8d3ce773190bc51a62 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:50:08 +0000 Subject: [PATCH 07/20] Update main.yml --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 978239d..bee4c80 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,8 +26,7 @@ jobs: - uses: actions/setup-node@v2 with: node-version: '14' - - run: pip install -r .github/requirements.txt - - run: node .github/ci-generateTranslations.js + - run: npm install jsdom && npm install axios - name: Create Pull Request uses: peter-evans/create-pull-request@v3 From 0573bb9191dbd86fca29d81f75925554b7f15500 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:52:12 +0000 Subject: [PATCH 08/20] Create .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file From bf3c1ee97cb84eead020b866db896e80c37a9711 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:57:30 +0000 Subject: [PATCH 09/20] Update main.yml --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bee4c80..25fa41a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,6 +27,7 @@ jobs: with: node-version: '14' - run: npm install jsdom && npm install axios + - run: node .github/ci-generateTranslations.js - name: Create Pull Request uses: peter-evans/create-pull-request@v3 From e69c5502b2d90701a711aaed4cce3dc3444651f2 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 18:58:04 +0000 Subject: [PATCH 10/20] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 40b878d..aee128d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +pagckage-lock.json \ No newline at end of file From 6284b3869430afe63e26ca9405ab54b052c44322 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 19:07:31 +0000 Subject: [PATCH 11/20] Update and rename main.yml to update_translations.yml --- .github/workflows/{main.yml => update_translations.yml} | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) rename .github/workflows/{main.yml => update_translations.yml} (81%) diff --git a/.github/workflows/main.yml b/.github/workflows/update_translations.yml similarity index 81% rename from .github/workflows/main.yml rename to .github/workflows/update_translations.yml index 25fa41a..91aff60 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/update_translations.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: Generate translations +name: Update translations # Controls when the action will run. on: @@ -30,4 +30,8 @@ jobs: - run: node .github/ci-generateTranslations.js - name: Create Pull Request uses: peter-evans/create-pull-request@v3 - + with: + commit-message: Generated updated translations + branch: generated_translations + title: "[OBSNinja Bot] Updated translations" + labels: i18n From f43f79a6cd52212ba524d7a705ac58f4c7f2b0fa Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 19:07:46 +0000 Subject: [PATCH 12/20] Update ci-generateTranslations.js --- .github/ci-generateTranslations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ci-generateTranslations.js b/.github/ci-generateTranslations.js index b51fa1c..e3dc087 100644 --- a/.github/ci-generateTranslations.js +++ b/.github/ci-generateTranslations.js @@ -25,7 +25,7 @@ function downloadTranslation(filename, trans = {}) { console.log("Saving translation: " + filename); const textDoc = JSON.stringify(trans, null, 2); - fs.writeFile(`..\\translations\\${filename}.json`, textDoc, function (err) { + fs.writeFile(`translations\\${filename}.json`, textDoc, function (err) { if (err) { return console.log(err); } From 4992858414d9dc40ceef2e425322bb0eaef6f80f Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 19:10:41 +0000 Subject: [PATCH 13/20] Update ci-generateTranslations.js --- .github/ci-generateTranslations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ci-generateTranslations.js b/.github/ci-generateTranslations.js index e3dc087..735f547 100644 --- a/.github/ci-generateTranslations.js +++ b/.github/ci-generateTranslations.js @@ -25,7 +25,7 @@ function downloadTranslation(filename, trans = {}) { console.log("Saving translation: " + filename); const textDoc = JSON.stringify(trans, null, 2); - fs.writeFile(`translations\\${filename}.json`, textDoc, function (err) { + fs.writeFile(`translations/${filename}.json`, textDoc, function (err) { if (err) { return console.log(err); } From 2cb96bb1335338dbb5428e6a21e93d8193587b01 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 19:32:51 +0000 Subject: [PATCH 14/20] Update ci-generateTranslations.js pull from the repo --- .github/ci-generateTranslations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ci-generateTranslations.js b/.github/ci-generateTranslations.js index 735f547..12b21d4 100644 --- a/.github/ci-generateTranslations.js +++ b/.github/ci-generateTranslations.js @@ -39,7 +39,7 @@ async function updateTranslation(filename) { // updates the website with a specific translation let data = await axios({ method: "get", - url: `https://obs.ninja/translations/${filename}.json?${( + url: `https://raw.githubusercontent.com/steveseguin/obsninja/master/translations/${filename}.json?${( Math.random() * 100 ).toString()}`, }).then(function (response) { From b113d53f15ec525995d8d46a655bb4263264d354 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 19:39:27 +0000 Subject: [PATCH 15/20] Update ci-generateTranslations.js --- .github/ci-generateTranslations.js | 62 ++++++++++++++---------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/.github/ci-generateTranslations.js b/.github/ci-generateTranslations.js index 12b21d4..f78062e 100644 --- a/.github/ci-generateTranslations.js +++ b/.github/ci-generateTranslations.js @@ -127,41 +127,35 @@ combinedTrans.placeholders = defaultTransPlaceholders; var counter = 0; for (const i in updateList) { const lang = updateList[i]; - setTimeout( - (ln) => { - var suceess = updateTranslation(ln); // we don't need to worry about DATA. - updateTranslation(ln).then(function (suceess) { - const newTrans = suceess[1]["innerHTML"]; - //const allItems = document.querySelectorAll('[data-translate]'); - allItems.forEach((ele) => { - const key = ele.dataset.translate; //.replace(/[\W]+/g, "-").toLowerCase(); - newTrans[key] = ele.innerHTML; - }); - const newTransTitles = suceess[1]["titles"]; - //const allTitles = document.querySelectorAll('[title]'); - allTitles.forEach((ele) => { - const key = ele.dataset.key; - newTransTitles[key] = ele.title; - }); + var translation = updateTranslation(lang); // we don't need to worry about DATA. + updateTranslation(lang).then(function (translation) { + const newTrans = translation[1]["innerHTML"]; + //const allItems = document.querySelectorAll('[data-translate]'); + allItems.forEach((ele) => { + const key = ele.dataset.translate; //.replace(/[\W]+/g, "-").toLowerCase(); + newTrans[key] = ele.innerHTML; + }); - const newPlaceholders = suceess[1]["placeholders"]; - // const allPlaceholders = document.querySelectorAll('[placeholder]'); - allPlaceholders.forEach((ele) => { - const key = ele.dataset.key; - newPlaceholders[key] = ele.placeholder; - }); + const newTransTitles = translation[1]["titles"]; + //const allTitles = document.querySelectorAll('[title]'); + allTitles.forEach((ele) => { + const key = ele.dataset.key; + newTransTitles[key] = ele.title; + }); - // //// DOWNLOAD UPDATED TRANSLATION - const outputTrans = {}; - outputTrans["titles"] = newTransTitles; - outputTrans["innerHTML"] = newTrans; - outputTrans["placeholders"] = newPlaceholders; - downloadTranslation(ln, outputTrans); - }); - }, - counter, - lang - ); - counter += 800; + const newPlaceholders = translation[1]["placeholders"]; + // const allPlaceholders = document.querySelectorAll('[placeholder]'); + allPlaceholders.forEach((ele) => { + const key = ele.dataset.key; + newPlaceholders[key] = ele.placeholder; + }); + + // //// DOWNLOAD UPDATED TRANSLATION + const outputTrans = {}; + outputTrans["titles"] = newTransTitles; + outputTrans["innerHTML"] = newTrans; + outputTrans["placeholders"] = newPlaceholders; + downloadTranslation(lang, outputTrans); + }); } From 57ec0db1ebb6b32aef579024d0ee011e40b9555d Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 20:47:51 +0000 Subject: [PATCH 16/20] typo --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index aee128d..ccb2c80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ node_modules/ -pagckage-lock.json \ No newline at end of file +package-lock.json \ No newline at end of file From b25614bd5fc35795bc3b18f9e279d123cea5abc8 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 20:51:14 +0000 Subject: [PATCH 17/20] Update update_translations.yml --- .github/workflows/update_translations.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update_translations.yml b/.github/workflows/update_translations.yml index 91aff60..370ebb1 100644 --- a/.github/workflows/update_translations.yml +++ b/.github/workflows/update_translations.yml @@ -5,10 +5,12 @@ name: Update translations # Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the master branch - #push: - # branches: [ master ] - #pull_request: - # branches: [ master ] + push: + paths: + - 'index.html' + - 'main.js' + branches: + - master # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From 66559c72b727e38b15390b707dc855919fecf835 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 20:52:07 +0000 Subject: [PATCH 18/20] what a mess... --- .github/requirements.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .github/requirements.txt diff --git a/.github/requirements.txt b/.github/requirements.txt deleted file mode 100644 index cef8ef7..0000000 --- a/.github/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -jsdom -axios \ No newline at end of file From b973e16396069a909801a4c87c7b4426bffa9d84 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 21:03:47 +0000 Subject: [PATCH 19/20] missing catches; format code --- .github/ci-generateTranslations.js | 66 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/.github/ci-generateTranslations.js b/.github/ci-generateTranslations.js index f78062e..c20f76e 100644 --- a/.github/ci-generateTranslations.js +++ b/.github/ci-generateTranslations.js @@ -42,9 +42,13 @@ async function updateTranslation(filename) { url: `https://raw.githubusercontent.com/steveseguin/obsninja/master/translations/${filename}.json?${( Math.random() * 100 ).toString()}`, - }).then(function (response) { - return response.data; - }); + }) + .then(function (response) { + return response.data; + }) + .catch(function (error) { + console.log(error); + }); const oldTransItems = data["innerHTML"]; @@ -129,33 +133,37 @@ for (const i in updateList) { const lang = updateList[i]; var translation = updateTranslation(lang); // we don't need to worry about DATA. - updateTranslation(lang).then(function (translation) { - const newTrans = translation[1]["innerHTML"]; - //const allItems = document.querySelectorAll('[data-translate]'); - allItems.forEach((ele) => { - const key = ele.dataset.translate; //.replace(/[\W]+/g, "-").toLowerCase(); - newTrans[key] = ele.innerHTML; - }); + updateTranslation(lang) + .then(function (translation) { + const newTrans = translation[1]["innerHTML"]; + //const allItems = document.querySelectorAll('[data-translate]'); + allItems.forEach((ele) => { + const key = ele.dataset.translate; //.replace(/[\W]+/g, "-").toLowerCase(); + newTrans[key] = ele.innerHTML; + }); - const newTransTitles = translation[1]["titles"]; - //const allTitles = document.querySelectorAll('[title]'); - allTitles.forEach((ele) => { - const key = ele.dataset.key; - newTransTitles[key] = ele.title; - }); + const newTransTitles = translation[1]["titles"]; + //const allTitles = document.querySelectorAll('[title]'); + allTitles.forEach((ele) => { + const key = ele.dataset.key; + newTransTitles[key] = ele.title; + }); - const newPlaceholders = translation[1]["placeholders"]; - // const allPlaceholders = document.querySelectorAll('[placeholder]'); - allPlaceholders.forEach((ele) => { - const key = ele.dataset.key; - newPlaceholders[key] = ele.placeholder; - }); + const newPlaceholders = translation[1]["placeholders"]; + // const allPlaceholders = document.querySelectorAll('[placeholder]'); + allPlaceholders.forEach((ele) => { + const key = ele.dataset.key; + newPlaceholders[key] = ele.placeholder; + }); - // //// DOWNLOAD UPDATED TRANSLATION - const outputTrans = {}; - outputTrans["titles"] = newTransTitles; - outputTrans["innerHTML"] = newTrans; - outputTrans["placeholders"] = newPlaceholders; - downloadTranslation(lang, outputTrans); - }); + // //// DOWNLOAD UPDATED TRANSLATION + const outputTrans = {}; + outputTrans["titles"] = newTransTitles; + outputTrans["innerHTML"] = newTrans; + outputTrans["placeholders"] = newPlaceholders; + downloadTranslation(lang, outputTrans); + }) + .catch(function (error) { + console.log(error); + }); } From 22f34d6b1ed0937343ec81d87259e898be6a2b83 Mon Sep 17 00:00:00 2001 From: Joel Calado Date: Sat, 27 Mar 2021 21:10:55 +0000 Subject: [PATCH 20/20] less verbose functions, safer for loop --- .github/ci-generateTranslations.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/ci-generateTranslations.js b/.github/ci-generateTranslations.js index c20f76e..54fb452 100644 --- a/.github/ci-generateTranslations.js +++ b/.github/ci-generateTranslations.js @@ -22,14 +22,13 @@ global.document = new JSDOM(``, { function downloadTranslation(filename, trans = {}) { // downloads the current translation to a file - console.log("Saving translation: " + filename); + console.log("Downloading translation: " + filename); const textDoc = JSON.stringify(trans, null, 2); fs.writeFile(`translations/${filename}.json`, textDoc, function (err) { if (err) { return console.log(err); } - console.log("The file was saved!"); }); return trans; @@ -129,7 +128,7 @@ combinedTrans.innerHTML = defaultTrans; combinedTrans.placeholders = defaultTransPlaceholders; var counter = 0; -for (const i in updateList) { +for (var i = 0; i < updateList.length; i++) { const lang = updateList[i]; var translation = updateTranslation(lang); // we don't need to worry about DATA.