improve script for resetting translated files (#16099)

* improve script for resetting translated files

* update script/README.md

Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com>
This commit is contained in:
Zeke Sikelianos 2020-10-16 12:16:56 -07:00 коммит произвёл GitHub
Родитель 5b725ddc27
Коммит 5f7243c3ff
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 61 добавлений и 20 удалений

Просмотреть файл

@ -30,6 +30,15 @@ Runs tests. Equivalent of `npm test`.
## Additional scripts
### [`anonymize-branch.js`](anonymize-branch.js)
Flatten all the commits in the current branch into a single anonymized @Octomerger commit
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`
---
### [`archive-enterprise-version.js`](archive-enterprise-version.js)
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
---
### [`new-versioning/update-not-fpt-conditionals.js`](new-versioning/update-not-fpt-conditionals.js)
Run this script to update these Liquid conditionals:
{% if currentVersion != 'free-pro-team@latest' %}
to:
{% if enterpriseServerVersions contains currentVersion %}
---
### [`new-versioning/update-products-yml.js`](new-versioning/update-products-yml.js)
@ -307,15 +329,7 @@ This script is run as a git precommit hook (installed by husky after npm install
### [`preview-openapi-changes`](preview-openapi-changes)
This script stitches and unstitches the `github/github` OpenAPI description via `rest-api-operations` to produce a local preview in docs-internal.
`github`, `rest-api-operations`, and `docs-internal` must share a parent directory locally.
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.
To stitch the repos together and do an npm build, pass the `stitch` argument.
To unstitch the repos and revert them to their pre-stitched state, pass the `unstitch` argument.
---
@ -379,13 +393,19 @@ Run this script to remove reusables and image files that exist in the repo but a
This is a convenience script for replacing the contents of translated files with the English content from their corresponding source file.
It's intended to be a workaround to temporarily bypass Crowdin parser bugs while we wait for Crowdin to fix them.
It's intended to be a workaround to temporarily bypass Crowdin parser bugs while we wait for translators to fix them.
Usage: script/reset-translated-File.js <relative-filename> [<two-letter-language-code>]
Usage: script/reset-translated-file.js <filename>
script/reset-translated-File.js content/desktop/foo.md -> resets all translations of foo.md
Examples:
script/reset-translated-File.js content/desktop/foo.md de -> resets german translation of foo.md
reset a single translated file using a relative path: $ script/reset-translated-file.js translations/es-XL/content/actions/index.md
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
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
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
---

Просмотреть файл

@ -6,17 +6,26 @@
// files with the English content from their corresponding source file.
//
// It's intended to be a workaround to temporarily bypass Crowdin parser bugs
// while we wait for Crowdin to fix them.
// while we wait for translators to fix them.
//
// Usage:
// script/reset-translated-File.js <relative-filename> [<two-letter-language-code>]
// script/reset-translated-file.js <filename>
//
// script/reset-translated-File.js content/desktop/foo.md
// -> resets all translations of foo.md
// Examples:
//
// script/reset-translated-File.js content/desktop/foo.md de
// -> resets german translation of foo.md
// reset a single translated file using a relative path:
// $ script/reset-translated-file.js translations/es-XL/content/actions/index.md
//
// 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
//
// 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
//
// 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
//
// [end-readme]
@ -25,8 +34,20 @@ const fs = require('fs')
const path = require('path')
const languages = require('../lib/languages')
const [relativePath, languageCode] = process.argv.slice(2)
assert(relativePath, 'first arg must be a target filename')
const [pathArg] = process.argv.slice(2)
assert(pathArg, 'first arg must be a target filename')
let languageCode
// Is the arg a fully-qualified path?
let relativePath = fs.existsSync(pathArg)
? path.relative(process.cwd(), pathArg)
: pathArg
// extract relative path and language code if pathArg is in the format `translations/<lang>/path/to/file`
if (relativePath.startsWith('translations/')) {
languageCode = Object.values(languages).find(language => relativePath.startsWith(language.dir) && language.code !== 'en').code
relativePath = relativePath.split(path.sep).slice(2).join(path.sep)
}
const englishFile = path.join(process.cwd(), relativePath)
assert(fs.existsSync(englishFile), `file does not exist: ${englishFile}`)