diff --git a/package.json b/package.json index 52e3fdfc4..a0b9c0bdd 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "license": "GPL-3.0-only", "dependencies": { "@cospired/i18n-iso-languages": "^2.1.0", + "@crowdin/crowdin-api-client": "^1.10.5", "@material-ui/core": "^4.11.3", "@material-ui/icons": "^4.11.2", "@material-ui/lab": "4.0.0-alpha.57", diff --git a/scripts/crowdin-fetch-latest.js b/scripts/crowdin-fetch-latest.js index 79c10a26c..f7a2a33fb 100644 --- a/scripts/crowdin-fetch-latest.js +++ b/scripts/crowdin-fetch-latest.js @@ -1,6 +1,13 @@ -const { CROWDIN_API_KEY } = require('../src/config'); +const crowdinTranslations = require('@crowdin/crowdin-api-client').Translations; -console.log('Pulling translations from CrowdIn.'); +const CROWDIN_TOKEN = process.env.CROWDIN_PERSONAL_TOKEN; +const CROWDIN_PROJECT_ID = 262825; + +// initialization of crowdin client +const credentials = { + token: CROWDIN_TOKEN +}; +const api = new crowdinTranslations(credentials); const https = require('https'); const fs = require('fs'); @@ -34,24 +41,25 @@ const downloadCboardJson = onComplete => { ); }; -const downloadTranslations = onComplete => { +const downloadTranslations = async onComplete => { console.log('Trying to download latest translation strings...'); + // get project build + const build = await api.listProjectBuilds(CROWDIN_PROJECT_ID); + const buildId = build.data[0].data.id; + const download = await api.downloadTranslations(CROWDIN_PROJECT_ID, buildId); const allTxZip = fs.createWriteStream(zipFilePath); - https.get( - `https://api.crowdin.com/api/project/cboard/download/all.zip?key=${CROWDIN_API_KEY}`, - function(response) { - response.pipe(allTxZip); - allTxZip.on('finish', function() { - console.log('Translation download complete.'); - allTxZip.close(onComplete); - }); - allTxZip.on('error', function(err) { - console.log('Translation download encountered error!'); - console.log(err); - }); - } - ); + https.get(download.data.url, function(response) { + response.pipe(allTxZip); + allTxZip.on('finish', function() { + console.log('Translation download complete.'); + allTxZip.close(onComplete); + }); + allTxZip.on('error', function(err) { + console.log('Translation download encountered error!'); + console.log(err); + }); + }); }; const deleteTemporaryDownloadFile = () => { @@ -90,7 +98,7 @@ const extractTranslations = () => { // delete directory recursively try { fs.rmdirSync(`${extractPath}/website`, { recursive: true }); - console.log(`website folded was deleted.`); + console.log(`website folder was deleted.`); } catch (err) { console.error(`Error while deleting ${extractPath}/website`); } @@ -104,6 +112,10 @@ const extractTranslations = () => { { source: 'sr-CS', dest: 'sr-RS' + }, + { + source: 'tu-TI', + dest: 'pt-TL' } ]; custom.forEach(data => { @@ -127,5 +139,6 @@ const extractTranslations = () => { }); }; -downloadCboardJson(() => null); +console.log('Pulling translations from CrowdIn...'); +//downloadCboardJson(() => null); downloadTranslations(extractTranslations); diff --git a/yarn.lock b/yarn.lock index 10b5572de..eb88c5b9e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1115,6 +1115,13 @@ resolved "https://registry.yarnpkg.com/@cospired/i18n-iso-languages/-/i18n-iso-languages-2.2.0.tgz#9236865c76291a9947bfd6ab8a285417cbd63369" integrity sha512-hywY9u9apWGeLxQuRcXw7IW0XkMdXum/hr3TpmHY2fAbXMTFlhhkPCdsQeHzjxMQwTnMgXaZ4j4WOCwKtlDRCQ== +"@crowdin/crowdin-api-client@^1.10.5": + version "1.10.5" + resolved "https://registry.yarnpkg.com/@crowdin/crowdin-api-client/-/crowdin-api-client-1.10.5.tgz#bfb499ed79bf626d55dd925eb0380b6293f4ec2d" + integrity sha512-Bcp60GkcRM4f34Q2/R5u3O1nEOseMQK06UuGROFDruH6OeoKNAicofVLqnJqErq53r9/35JkKgFnVD+eCbQ49A== + dependencies: + axios "^0.21.1" + "@csstools/convert-colors@^1.4.0": version "1.4.0" resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"