Skip to content

Commit

Permalink
updated script to use crowdin api 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbedouret committed Apr 7, 2021
1 parent 4c5eb60 commit 91c7ac5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
51 changes: 32 additions & 19 deletions scripts/crowdin-fetch-latest.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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`);
}
Expand All @@ -104,6 +112,10 @@ const extractTranslations = () => {
{
source: 'sr-CS',
dest: 'sr-RS'
},
{
source: 'tu-TI',
dest: 'pt-TL'
}
];
custom.forEach(data => {
Expand All @@ -127,5 +139,6 @@ const extractTranslations = () => {
});
};

downloadCboardJson(() => null);
console.log('Pulling translations from CrowdIn...');
//downloadCboardJson(() => null);
downloadTranslations(extractTranslations);
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 91c7ac5

Please sign in to comment.