Skip to content

Commit 7b7d78e

Browse files
authored
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
1 parent 9eadcaf commit 7b7d78e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

script/i18n/reset-files-with-broken-liquid-tags.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
22

33
import program from 'commander'
4+
import { execSync } from 'child_process'
45
import { languageFiles, compareLiquidTags } from '../../lib/liquid-tags/tokens.js'
56
import languages from '../../lib/languages.js'
6-
import fs from 'fs'
77

88
program
99
.description('show-liquid-tags-diff')
@@ -12,15 +12,15 @@ program
1212
.parse(process.argv)
1313

1414
function resetFiles(files) {
15-
console.log(`Files to be reset (${files.length}): \n${files.join('\n')}`)
15+
console.log(`Reseting ${files.length} files:`)
1616

17-
files.forEach((file) => {
18-
// remove file so it falls back to English
19-
console.log(`removing ${file}`)
17+
const dryRun = program.opts().dryRun ? '--dry-run' : ''
2018

21-
if (!program.opts().dryRun) {
22-
fs.unlinkSync(file)
23-
}
19+
files.forEach((file) => {
20+
execSync(
21+
`script/i18n/reset-translated-file.js ${file} --reason="broken liquid tags" ${dryRun}`,
22+
{ stdio: 'inherit' }
23+
)
2424
})
2525
}
2626

script/i18n/reset-translated-file.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ const resetToEnglishSource = (translationFilePath) => {
5757
}
5858

5959
if (!dryRun) {
60-
// replace file with English source
60+
// it is important to replace the file with English source instead of
61+
// removing it, and relying on the fallback, because redired_from frontmatter
62+
// won't work in fallbacks
6163
const englishContent = fs.readFileSync(englishFile, 'utf8')
6264
fs.writeFileSync(translationFilePath, englishContent)
6365
}
66+
6467
console.log(
6568
'-> reverted to English: %s %s',
6669
path.relative(process.cwd(), translationFilePath),

0 commit comments

Comments
 (0)