From 7b7d78e12656297cc1f654996121133d5f4579d8 Mon Sep 17 00:00:00 2001 From: Marcelo Jacobus Date: Tue, 30 Nov 2021 10:06:20 -0300 Subject: [PATCH] Properly reset files with broken liquid tags (#23151) * Fix: Properly reset files with broken liquid tags * Add a comment clarifying why we reset translations the way we do --- .../i18n/reset-files-with-broken-liquid-tags.js | 16 ++++++++-------- script/i18n/reset-translated-file.js | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/script/i18n/reset-files-with-broken-liquid-tags.js b/script/i18n/reset-files-with-broken-liquid-tags.js index 8996d2f61f..987c191201 100644 --- a/script/i18n/reset-files-with-broken-liquid-tags.js +++ b/script/i18n/reset-files-with-broken-liquid-tags.js @@ -1,9 +1,9 @@ #!/usr/bin/env node import program from 'commander' +import { execSync } from 'child_process' import { languageFiles, compareLiquidTags } from '../../lib/liquid-tags/tokens.js' import languages from '../../lib/languages.js' -import fs from 'fs' program .description('show-liquid-tags-diff') @@ -12,15 +12,15 @@ program .parse(process.argv) function resetFiles(files) { - console.log(`Files to be reset (${files.length}): \n${files.join('\n')}`) + console.log(`Reseting ${files.length} files:`) + + const dryRun = program.opts().dryRun ? '--dry-run' : '' files.forEach((file) => { - // remove file so it falls back to English - console.log(`removing ${file}`) - - if (!program.opts().dryRun) { - fs.unlinkSync(file) - } + execSync( + `script/i18n/reset-translated-file.js ${file} --reason="broken liquid tags" ${dryRun}`, + { stdio: 'inherit' } + ) }) } diff --git a/script/i18n/reset-translated-file.js b/script/i18n/reset-translated-file.js index 952e7fbd46..844d79a049 100755 --- a/script/i18n/reset-translated-file.js +++ b/script/i18n/reset-translated-file.js @@ -57,10 +57,13 @@ const resetToEnglishSource = (translationFilePath) => { } if (!dryRun) { - // replace file with English source + // it is important to replace the file with English source instead of + // removing it, and relying on the fallback, because redired_from frontmatter + // won't work in fallbacks const englishContent = fs.readFileSync(englishFile, 'utf8') fs.writeFileSync(translationFilePath, englishContent) } + console.log( '-> reverted to English: %s %s', path.relative(process.cwd(), translationFilePath),