forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements in tools to help merge crowdin PRs (github#18409)
- add `script/test-render-translation.js` to render all translated content to catch malformed liquid that would cause render errors - improve test output for `script/fix-translation-errors.js` and `tests/content/lint-files.js` - make it so `script/reset-translated-file.js` can handle files that have been renamed
- Loading branch information
1 parent
3899af0
commit a8d54c9
Showing
8 changed files
with
348 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const renderContent = require('../lib/render-content') | ||
const loadSiteData = require('../lib/site-data') | ||
const { loadPages } = require('../lib/pages') | ||
const languages = require('../lib/languages') | ||
const path = require('path') | ||
const { execSync } = require('child_process') | ||
const fs = require('fs') | ||
const frontmatter = require('../lib/frontmatter') | ||
const chalk = require('chalk') | ||
|
||
const main = async () => { | ||
const siteData = loadSiteData() | ||
const pages = await loadPages() | ||
const contextByLanguage = {} | ||
for (const lang in languages) { | ||
const langObj = languages[lang] | ||
const [crowdinLangCode] = langObj.dir === '' ? 'en' : langObj.dir.split('/').slice(1) | ||
if (!crowdinLangCode) continue | ||
contextByLanguage[crowdinLangCode] = { | ||
site: siteData[langObj.code].site, | ||
currentLanguage: langObj.code, | ||
currentVersion: 'free-pro-team@latest' | ||
} | ||
} | ||
|
||
const rootDir = path.join(__dirname, '..') | ||
|
||
const changedFilesRelPaths = execSync('git diff --name-only origin/main | egrep "^translations/.*/.+.md$"', { maxBuffer: 1024 * 1024 * 100 }) | ||
.toString() | ||
.split('\n') | ||
.filter(path => path !== '' && !path.endsWith('README.md')) | ||
.sort() | ||
|
||
console.log(`Found ${changedFilesRelPaths.length} translated files.`) | ||
|
||
changedFilesRelPaths.forEach(async (relPath) => { | ||
const fullPath = path.join(rootDir, relPath) | ||
const lang = relPath.split('/')[1] | ||
const context = { | ||
...contextByLanguage[lang], | ||
pages, | ||
page: pages.find(page => page.fullPath === fullPath), | ||
redirects: {} | ||
} | ||
if (!context.page && !relPath.includes('data/reusables')) return | ||
const fileContents = await fs.promises.readFile(fullPath, 'utf8') | ||
const { content } = frontmatter(fileContents) | ||
try { | ||
await renderContent.liquid.parseAndRender(content, context) | ||
} catch (err) { | ||
console.log(chalk.bold(relPath)) | ||
console.log(chalk.red(` error message: ${err.message}`)) | ||
} | ||
}) | ||
} | ||
|
||
main() |
Oops, something went wrong.