Skip to content

Commit fe3c3ca

Browse files
authored
Develop (#1983)
Develop
2 parents 5878c2d + 75a8614 commit fe3c3ca

File tree

721 files changed

+4406
-64308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

721 files changed

+4406
-64308
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ cypress/videos
2020
# Dynamically parsed data
2121

2222
source/_data/banners.yml
23+
24+
# Translations
25+
# By default we ignore each translation folder like "source/ja",
26+
# During the build, We copy English file for each untranslated page to
27+
# the language folder - if there is no fully translated file there.
28+
# Thus when you add a new translation, add it to the source control
29+
# with "git add --force" command to override the folder.
30+
#
31+
source/ja
32+
source/zh-cn
33+

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"eslint.enable": true,
3-
"editor.formatOnSave": false
3+
"editor.formatOnSave": false,
4+
"workbench.colorCustomizations": {}
45
}

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Our currently supported languages can be found at [`/source/_data/languages.yml`
167167

168168
Translate existing documentation then submit a [pull request](#Pull-Requests) for your change.
169169

170+
If a page does not have a translation, then a pre-start step copies the English file to the language folder. These copies should NOT be committed into the source code. Only when the file has been translated you can add it to the source code with `git add --force source/<language>/.../file.md` and this file will not be overwritten by the English file.
171+
170172
## Committing Code
171173

172174
### Linting

PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,3 @@ Thanks for contributing!
44
Please explain what changes were made
55
also reference any fixed issues with "close #[ISSUE]"
66
-->
7-
8-
### Translations updated
9-
10-
Changes made to documentation were also copied over to other languages (**copying English text is ok**).
11-
12-
- [ ] Japanese docs in [`/source/ja`](/source/ja).
13-
- [ ] Chinese docs in [`/source/zh-cn`](/source/zh-cn).
14-
- [ ] Not applicable (this is not a change to an `en` doc content).

copy-english-docs.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// @ts-check
2+
3+
const debug = require('debug')('copy-english-docs')
4+
const execa = require('execa')
5+
const R = require('ramda')
6+
const pluralize = require('pluralize')
7+
const fs = require('fs-extra')
8+
const Promise = require('bluebird')
9+
const path = require('path')
10+
11+
// work in progress
12+
/* eslint-disable no-console */
13+
14+
const getLanguageName = (short) => {
15+
const names = {
16+
ja: 'Japanese',
17+
'zh-cn': 'Chinese',
18+
}
19+
20+
if (!names[short]) {
21+
throw new Error(`Unknown language short name ${short}`)
22+
}
23+
24+
return names[short]
25+
}
26+
27+
const findFilesTrackedByGit = (folder) => {
28+
return execa('git', ['ls-files', folder]).then(R.prop('stdout')).then(R.split('\n'))
29+
}
30+
31+
const removePrefix = (prefix) => {
32+
const n = prefix.length + 1 // prefix + "/"
33+
34+
const remove = (relativeFilename) => {
35+
return R.startsWith(prefix, relativeFilename) ? relativeFilename.substr(n) : relativeFilename
36+
}
37+
38+
return R.map(remove)
39+
}
40+
41+
const findAllDocs = () => {
42+
debug('finding all docs')
43+
44+
const sourcesFolderName = 'source'
45+
46+
return findFilesTrackedByGit(sourcesFolderName)
47+
}
48+
49+
const isJapaneseDoc = R.test(/\/ja\//)
50+
const isChineseDoc = R.test(/\/zh-cn\//)
51+
const isImage = R.test(/\/img\//)
52+
const isTranslation = R.anyPass([isJapaneseDoc, isChineseDoc, isImage])
53+
54+
const translationsFilter = R.reject(isTranslation)
55+
56+
const findAllEnglishDocs = () => {
57+
debug('finding tracked English docs')
58+
59+
return findAllDocs().then(translationsFilter).then(removePrefix('source'))
60+
}
61+
62+
/**
63+
* @param {("ja" | "zh-cn")} shortName The short language name
64+
*/
65+
const findAllDocsFor = (shortName) => {
66+
const relativeSourceFolder = `source/${shortName}`
67+
68+
return findFilesTrackedByGit(relativeSourceFolder).then(removePrefix(relativeSourceFolder))
69+
}
70+
71+
/**
72+
* @param {("ja" | "zh-cn")} targetLanguage
73+
*/
74+
const copyAllEnglishDocsNotTranslatedTo = (targetLanguage) => {
75+
return Promise.all([
76+
findAllEnglishDocs(),
77+
findAllDocsFor(targetLanguage),
78+
]).then(([englishFiles, translatedFiles]) => {
79+
return R.difference(englishFiles, translatedFiles)
80+
})
81+
.then((untransledEnglishFiles) => {
82+
if (!untransledEnglishFiles.length) {
83+
console.log('No untranslated English docs compared to %s', getLanguageName(targetLanguage))
84+
85+
return
86+
}
87+
88+
console.log('Copying %s from English to %s',
89+
pluralize('file', untransledEnglishFiles.length, true), getLanguageName(targetLanguage))
90+
console.table(untransledEnglishFiles)
91+
92+
return Promise.mapSeries(untransledEnglishFiles, (relativePathToEnglishFile) => {
93+
const sourcePath = path.join('source', relativePathToEnglishFile)
94+
const destinationPath = path.join('source', targetLanguage, relativePathToEnglishFile)
95+
const destinationFolder = path.dirname(destinationPath)
96+
97+
return fs.ensureDir(destinationFolder)
98+
.then(() => {
99+
return fs.copyFile(sourcePath, destinationPath)
100+
})
101+
102+
})
103+
})
104+
}
105+
106+
const copyUntranslatedDocs = () => {
107+
return copyAllEnglishDocsNotTranslatedTo('ja')
108+
.then(() => {
109+
return copyAllEnglishDocsNotTranslatedTo('zh-cn')
110+
})
111+
112+
}
113+
114+
// allow using module.parent
115+
// @ts-ignore
116+
if (!module.parent) {
117+
copyUntranslatedDocs()
118+
} else {
119+
module.exports = {
120+
copyUntranslatedDocs,
121+
}
122+
}

cy_scripts/should-deploy.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,28 @@ const Promise = require('bluebird')
1010

1111
const docsChanged = complement(isEmpty)
1212

13-
const isForced = process.argv.some(equals('--force'))
13+
/**
14+
* Checks if a given environment variable is present
15+
* and has a string value that can be considered truthy, like
16+
* "true", "TRUE", "on", "1", "yes"
17+
*
18+
* @param {string} name of the environment variable to check
19+
* @returns boolean
20+
*/
21+
const isEnvVariableOn = (name) => {
22+
const value = process.env[name]
23+
24+
if (!value) {
25+
return false
26+
}
27+
28+
return value === 'true'
29+
|| value === 'TRUE'
30+
|| value === 'on'
31+
|| value === '1'
32+
|| value === 'yes'
33+
}
34+
const isForced = process.argv.some(equals('--force')) || isEnvVariableOn('FORCE_DEPLOY')
1435

1536
const isValidEnvironment = is.oneOf(['staging', 'production'])
1637

cypress/integration/page_header_spec.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ describe('Page Header', () => {
77
})
88

99
it('displays correct page title', function () {
10-
cy.wrap(this.langValues).each(function (lang) {
10+
// disabling this test because we are copying untranslated English document pages
11+
// into other language folders. A single translated page title is not enough to count
12+
// thus the sidebar has translated title, but the page itself shows English translation
13+
// limit to English instead of "this.langValues"
14+
const languages = ['en']
15+
16+
cy.wrap(languages).each(function (lang) {
1117
let sidebarYaml = 'source/_data/sidebar.yml'
1218
let visitUrlPrefix = ''
1319

@@ -55,21 +61,36 @@ describe('Page Header', () => {
5561
})
5662
})
5763

58-
it('should have link to edit doc', function () {
59-
cy.wrap(this.MAIN_NAV).each((nav) => {
60-
let path = `${nav.path}.html`
61-
let mdPath = `${nav.path}.md`
64+
it('should have link to edit doc in each language', function () {
65+
cy.wrap(this.langValues).each(function (lang) {
66+
// In English it probably is "Improve this doc",
67+
// and in other languages it is a translation
68+
const improvePageText = this[lang].page.improve
6269

63-
if (nav.path === '/plugins/') {
64-
path = `${nav.path}index.html`
65-
mdPath = `${nav.path}index.md`
70+
cy.log(`Language **${lang}**`)
71+
let visitUrlPrefix = ''
72+
73+
if (lang !== 'en') {
74+
visitUrlPrefix = lang
6675
}
6776

68-
cy.visit(path)
69-
cy.contains('a', 'Improve this doc').as('editLink')
70-
.should('have.attr', 'href')
71-
.and('include', mdPath)
72-
.and('include', this.improveUrl)
77+
cy.wrap(this.MAIN_NAV).each((nav) => {
78+
let path = `${nav.path}.html`
79+
let mdPath = `${nav.path}.md`
80+
81+
if (nav.path === '/plugins/') {
82+
path = `${nav.path}index.html`
83+
mdPath = `${nav.path}index.md`
84+
}
85+
86+
cy.visit(`${visitUrlPrefix}${path}`)
87+
88+
89+
cy.contains('a', improvePageText).as('editLink')
90+
.should('have.attr', 'href')
91+
.and('include', mdPath)
92+
.and('include', this.improveUrl)
93+
})
7394
})
7495
})
7596
})

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ process.on('unhandledRejection', function (reason, p) {
55
process.exit(-1)
66
})
77

8+
const { copyUntranslatedDocs } = require('./copy-english-docs')
89
const Hexo = require('hexo')
910
const chalk = require('chalk')
1011
const minimist = require('minimist')
@@ -149,4 +150,5 @@ function initHexo () {
149150
})
150151
}
151152

152-
initHexo()
153+
copyUntranslatedDocs()
154+
.then(initHexo)

0 commit comments

Comments
 (0)