Skip to content

Commit 5f7243c

Browse files
zekechiedo
andauthored
improve script for resetting translated files (github#16099)
* improve script for resetting translated files * update script/README.md Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com>
1 parent 5b725dd commit 5f7243c

File tree

2 files changed

+61
-20
lines changed

2 files changed

+61
-20
lines changed

script/README.md

+32-12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ Runs tests. Equivalent of `npm test`.
3030

3131
## Additional scripts
3232

33+
### [`anonymize-branch.js`](anonymize-branch.js)
34+
35+
Flatten all the commits in the current branch into a single anonymized @Octomerger commit
36+
37+
Usage: script/anonymize-branch.js <new-commit-message> [base-branch] Example: script/anonymize-branch.js "nothing to see here" If the optional [base-branch] argument is omitted, it will default to `main`
38+
39+
---
40+
41+
3342
### [`archive-enterprise-version.js`](archive-enterprise-version.js)
3443

3544
Run this script during the Enterprise deprecation process to download static copies of all pages for the oldest supported Enterprise version. See the Enterprise deprecation issue template for instructions.
@@ -270,6 +279,19 @@ Usage $ script/new-versioning/main
270279
---
271280

272281

282+
### [`new-versioning/update-not-fpt-conditionals.js`](new-versioning/update-not-fpt-conditionals.js)
283+
284+
Run this script to update these Liquid conditionals:
285+
286+
{% if currentVersion != 'free-pro-team@latest' %}
287+
288+
to:
289+
290+
{% if enterpriseServerVersions contains currentVersion %}
291+
292+
---
293+
294+
273295
### [`new-versioning/update-products-yml.js`](new-versioning/update-products-yml.js)
274296

275297

@@ -307,15 +329,7 @@ This script is run as a git precommit hook (installed by husky after npm install
307329

308330
### [`preview-openapi-changes`](preview-openapi-changes)
309331

310-
This script stitches and unstitches the `github/github` OpenAPI description via `rest-api-operations` to produce a local preview in docs-internal.
311-
312-
`github`, `rest-api-operations`, and `docs-internal` must share a parent directory locally.
313-
314-
You must bootstrap `github` for this script to work. To check if you need to bootstrap, check if the `bin` directory in `github` exists locally. If it does not exist, run `./script/bootstrap` from the `github` directory.
315332

316-
To stitch the repos together and do an npm build, pass the `stitch` argument.
317-
318-
To unstitch the repos and revert them to their pre-stitched state, pass the `unstitch` argument.
319333

320334
---
321335

@@ -379,13 +393,19 @@ Run this script to remove reusables and image files that exist in the repo but a
379393

380394
This is a convenience script for replacing the contents of translated files with the English content from their corresponding source file.
381395

382-
It's intended to be a workaround to temporarily bypass Crowdin parser bugs while we wait for Crowdin to fix them.
396+
It's intended to be a workaround to temporarily bypass Crowdin parser bugs while we wait for translators to fix them.
397+
398+
Usage: script/reset-translated-file.js <filename>
399+
400+
Examples:
401+
402+
reset a single translated file using a relative path: $ script/reset-translated-file.js translations/es-XL/content/actions/index.md
383403

384-
Usage: script/reset-translated-File.js <relative-filename> [<two-letter-language-code>]
404+
reset a single translated file using a full path: $ script/reset-translated-file.js /Users/z/git/github/docs-internal/translations/es-XL/content/actions/index.md
385405

386-
script/reset-translated-File.js content/desktop/foo.md -> resets all translations of foo.md
406+
reset all language variants of a single English file (using a relative path): $ script/reset-translated-file.js content/actions/index.md $ script/reset-translated-file.js data/ui.yml
387407

388-
script/reset-translated-File.js content/desktop/foo.md de -> resets german translation of foo.md
408+
reset all language variants of a single English file (using a full path): $ script/reset-translated-file.js /Users/z/git/github/docs-internal/content/desktop/index.md $ script/reset-translated-file.js /Users/z/git/github/docs-internal/data/ui.yml
389409

390410
---
391411

script/reset-translated-file.js

+29-8
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@
66
// files with the English content from their corresponding source file.
77
//
88
// It's intended to be a workaround to temporarily bypass Crowdin parser bugs
9-
// while we wait for Crowdin to fix them.
9+
// while we wait for translators to fix them.
1010
//
1111
// Usage:
12-
// script/reset-translated-File.js <relative-filename> [<two-letter-language-code>]
12+
// script/reset-translated-file.js <filename>
1313
//
14-
// script/reset-translated-File.js content/desktop/foo.md
15-
// -> resets all translations of foo.md
14+
// Examples:
1615
//
17-
// script/reset-translated-File.js content/desktop/foo.md de
18-
// -> resets german translation of foo.md
16+
// reset a single translated file using a relative path:
17+
// $ script/reset-translated-file.js translations/es-XL/content/actions/index.md
1918
//
19+
// reset a single translated file using a full path:
20+
// $ script/reset-translated-file.js /Users/z/git/github/docs-internal/translations/es-XL/content/actions/index.md
21+
//
22+
// reset all language variants of a single English file (using a relative path):
23+
// $ script/reset-translated-file.js content/actions/index.md
24+
// $ script/reset-translated-file.js data/ui.yml
25+
//
26+
// reset all language variants of a single English file (using a full path):
27+
// $ script/reset-translated-file.js /Users/z/git/github/docs-internal/content/desktop/index.md
28+
// $ script/reset-translated-file.js /Users/z/git/github/docs-internal/data/ui.yml
2029
//
2130
// [end-readme]
2231

@@ -25,8 +34,20 @@ const fs = require('fs')
2534
const path = require('path')
2635
const languages = require('../lib/languages')
2736

28-
const [relativePath, languageCode] = process.argv.slice(2)
29-
assert(relativePath, 'first arg must be a target filename')
37+
const [pathArg] = process.argv.slice(2)
38+
assert(pathArg, 'first arg must be a target filename')
39+
let languageCode
40+
41+
// Is the arg a fully-qualified path?
42+
let relativePath = fs.existsSync(pathArg)
43+
? path.relative(process.cwd(), pathArg)
44+
: pathArg
45+
46+
// extract relative path and language code if pathArg is in the format `translations/<lang>/path/to/file`
47+
if (relativePath.startsWith('translations/')) {
48+
languageCode = Object.values(languages).find(language => relativePath.startsWith(language.dir) && language.code !== 'en').code
49+
relativePath = relativePath.split(path.sep).slice(2).join(path.sep)
50+
}
3051

3152
const englishFile = path.join(process.cwd(), relativePath)
3253
assert(fs.existsSync(englishFile), `file does not exist: ${englishFile}`)

0 commit comments

Comments
 (0)