Skip to content

Commit 18a54dd

Browse files
authored
Display all files reset in a translation batch (#23152)
* Output every file reset * Add --dry-run and --reason options to reset-translated-file.js * Output reason when reset-translated-file.js script is called
1 parent 855034f commit 18a54dd

4 files changed

Lines changed: 31 additions & 10 deletions

File tree

script/i18n/lint-translation-files.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ function lintAndResetFiles(checkType) {
7979
// We are not passing --prefer-main because we want to remove the file so we
8080
// reset it directly to the English source
8181
filesToReset.forEach((file) => {
82-
execSync(`script/i18n/reset-translated-file.js ${file}`)
82+
execSync(`script/i18n/reset-translated-file.js ${file} --reason="${checkType} error"`, {
83+
stdio: 'inherit',
84+
})
8385
})
8486

8587
// Print a message with next steps

script/i18n/reset-known-broken-translation-files.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ async function main() {
5050
// This is done sequentially to ensure only one Git operation is running at any given time.
5151
brokenFilesArray.forEach((file) => {
5252
console.log(`Resetting ${file}`)
53-
execSync(`node script/i18n/reset-translated-file.js ${file}`)
53+
execSync(
54+
`script/i18n/reset-translated-file.js ${file} --reason="Listed in localization-support#489"`,
55+
{ stdio: 'inherit' }
56+
)
5457
})
5558

5659
// Print a message with next steps.

script/i18n/reset-translated-file.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ program
3030
'-m, --prefer-main',
3131
'Reset file to the translated file, try using the file from `main` branch first, if not found (usually due to renaming), fall back to English source.'
3232
)
33+
.option('-d, --dry-run', 'Just pretend to reset files')
34+
.option('-r, --reason <reason>', 'A reason why the file is getting reset')
3335
.parse(process.argv)
3436

37+
const dryRun = program.opts().dryRun
38+
const reason = program.opts().reason
39+
const reasonMessage = reason ? `Reason: ${reason}` : ''
40+
3541
const resetToEnglishSource = (translationFilePath) => {
3642
assert(
3743
translationFilePath.startsWith('translations/'),
@@ -45,15 +51,21 @@ const resetToEnglishSource = (translationFilePath) => {
4551
const relativePath = translationFilePath.split(path.sep).slice(2).join(path.sep)
4652
const englishFile = path.join(process.cwd(), relativePath)
4753

48-
if (!fs.existsSync(englishFile)) {
54+
if (!dryRun && !fs.existsSync(englishFile)) {
4955
fs.unlinkSync(translationFilePath)
5056
return
5157
}
5258

53-
// replace file with English source
54-
const englishContent = fs.readFileSync(englishFile, 'utf8')
55-
fs.writeFileSync(translationFilePath, englishContent)
56-
console.log('-> reverted to English: %s', path.relative(process.cwd(), translationFilePath))
59+
if (!dryRun) {
60+
// replace file with English source
61+
const englishContent = fs.readFileSync(englishFile, 'utf8')
62+
fs.writeFileSync(translationFilePath, englishContent)
63+
}
64+
console.log(
65+
'-> reverted to English: %s %s',
66+
path.relative(process.cwd(), translationFilePath),
67+
reasonMessage
68+
)
5769
}
5870

5971
const [pathArg] = program.args
@@ -64,8 +76,10 @@ const relativePath = fs.existsSync(pathArg) ? path.relative(process.cwd(), pathA
6476

6577
if (program.opts().preferMain) {
6678
try {
67-
execSync(`git checkout main -- ${relativePath}`, { stdio: 'pipe' })
68-
console.log('-> reverted to file from main branch: %s', relativePath)
79+
if (!dryRun) {
80+
execSync(`git checkout main -- ${relativePath}`, { stdio: 'pipe' })
81+
}
82+
console.log('-> reverted to file from main branch: %s %s', relativePath, reasonMessage)
6983
} catch (e) {
7084
if (e.message.includes('pathspec')) {
7185
console.warn(

script/i18n/test-render-translation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ async function loadAndPatchSiteData(filesWithKnownIssues = {}) {
9494

9595
// Reset the file
9696
console.warn(`resetting file "${relPath}" due to loadSiteData error: ${error.toString()}`)
97-
await exec(`script/i18n/reset-translated-file.js --prefer-main ${relPath}`)
97+
await exec(
98+
`script/i18n/reset-translated-file.js --prefer-main ${relPath} --reason="loadSiteData error"`
99+
)
98100

99101
// Try to load the site data again
100102
return loadAndPatchSiteData(filesWithKnownIssues)

0 commit comments

Comments
 (0)