From d3c96148a457650ca350fd4aa7633bb0d17c594f Mon Sep 17 00:00:00 2001 From: per1234 Date: Tue, 25 Jul 2023 21:39:21 -0700 Subject: [PATCH] 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. --- scripts/i18n/transifex-pull.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/i18n/transifex-pull.js b/scripts/i18n/transifex-pull.js index e620e88da..b92a67cf1 100644 --- a/scripts/i18n/transifex-pull.js +++ b/scripts/i18n/transifex-pull.js @@ -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({