feat(tools): Script to delete all translations of a language on Crowdin (#41380)
This commit is contained in:
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
This one-off script can be used to delete all existing translations for a specified language on Crowdin.
|
||||||
|
|
||||||
|
Specifying a projectId and lanaguageId in the .env file allows the script to accomplish this task.
|
||||||
|
*/
|
||||||
|
|
||||||
|
require('dotenv').config({ path: `${__dirname}/../.env` });
|
||||||
|
|
||||||
|
const {
|
||||||
|
getLanguageTranslations,
|
||||||
|
deleteLanguageTranslations
|
||||||
|
} = require('../utils/strings');
|
||||||
|
|
||||||
|
const projectId = process.env.CROWDIN_PROJECT_ID;
|
||||||
|
const languageId = process.env.CROWDIN_LANGUAGE_ID;
|
||||||
|
|
||||||
|
(async (projectId, languageId) => {
|
||||||
|
console.log('starting script...');
|
||||||
|
const translations = await getLanguageTranslations({
|
||||||
|
projectId,
|
||||||
|
languageId
|
||||||
|
});
|
||||||
|
if (translations && translations.length) {
|
||||||
|
for (let translation of translations) {
|
||||||
|
const { stringId } = translation.data;
|
||||||
|
await deleteLanguageTranslations(projectId, languageId, stringId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('complete');
|
||||||
|
})(projectId, languageId);
|
4
tools/crowdin/sample.env
Normal file
4
tools/crowdin/sample.env
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
CROWDIN_PROJECT_ID=
|
||||||
|
CROWDIN_PERSONAL_TOKEN=
|
||||||
|
CROWDIN_API_URL='https://freecodecamp.crowdin.com/api/v2/'
|
||||||
|
CROWDIN_LANGUAGE_ID=
|
@ -212,6 +212,18 @@ const getLanguageTranslations = async ({ projectId, languageId }) => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteLanguageTranslations = async (projectId, languageId, stringId) => {
|
||||||
|
let headers = { ...authHeader };
|
||||||
|
const endPoint = `projects/${projectId}/translations?languageId=${languageId}&stringId=${stringId}`;
|
||||||
|
console.log(`deleting ${stringId}...`);
|
||||||
|
await makeRequest({
|
||||||
|
method: 'delete',
|
||||||
|
endPoint,
|
||||||
|
headers
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getStrings,
|
getStrings,
|
||||||
updateString,
|
updateString,
|
||||||
@ -220,5 +232,6 @@ module.exports = {
|
|||||||
getStringTranslations,
|
getStringTranslations,
|
||||||
addTranslation,
|
addTranslation,
|
||||||
deleteTranslation,
|
deleteTranslation,
|
||||||
getLanguageTranslations
|
getLanguageTranslations,
|
||||||
|
deleteLanguageTranslations
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user