Clean localization data files before pulling from Transifex

The localization of the UI strings specific to the Arduino IDE application is done via the Transifex localization
platform. A scheduled workflow pulls the data from Transifex weekly and submits a pull request for the updates.

Previously, the script used to pull the data did not clean the data files before pulling. This meant that a vestigial
file would accumulate in the repository whenever a language was removed from the Transifex project.

The accumulation is avoided by deleting the data files for the locales managed on Transifex (all locales other than the
source English locale) before downloading the data from Transifex.
This commit is contained in:
per1234 2023-07-25 21:39:21 -07:00
parent e17472ef07
commit 144df893d0

View File

@ -1,6 +1,8 @@
// @ts-check
const transifex = require('./transifex');
const path = require('path');
const fs = require('node:fs/promises');
const util = require('util');
const shell = require('shelljs');
const fetch = require('node-fetch');
@ -106,6 +108,15 @@ const getTranslationDownloadStatus = async (language, downloadRequestId) => {
const languages = await getLanguages(organization, project);
shell.echo('translations found:', languages.join(', '));
// Remove data managed on Transifex to avoid accumulation of vestigial files
const translationFilenames = await fs.readdir(translationsDirectory);
for (const filename of translationFilenames) {
if (filename === 'en.json' || !filename.endsWith('.json')) {
continue;
}
await fs.unlink(path.join(translationsDirectory, filename));
}
let downloadIds = [];
for (const language of languages) {
downloadIds.push({