Skip to content

Commit cf76bcf

Browse files
authored
Merge pull request #23206 from github/repo-sync
repo sync
2 parents b70cc43 + f7be7f0 commit cf76bcf

File tree

10 files changed

+46
-30
lines changed

10 files changed

+46
-30
lines changed

.github/workflows/link-check-on-pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ jobs:
8686
SHOULD_COMMENT: ${{ secrets.DOCS_BOT_FR != '' }}
8787
CHECK_EXTERNAL_LINKS: false
8888
CREATE_REPORT: false
89+
# Not strictly necessary bit it makes warmServer() a bit faster
90+
# because it only bothers with English to begin with, which
91+
# we're filtering on anyway once the list of all pages has
92+
# been loaded.
93+
ENABLED_LANGUAGES: en
8994
run: node .github/actions-scripts/rendered-content-link-checker.js
9095

9196
- name: Upload artifact(s)

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,8 @@ jobs:
168168
env:
169169
DIFF_FILE: get_diff_files.txt
170170
CHANGELOG_CACHE_FILE_PATH: tests/fixtures/changelog-feed.json
171+
# By default, when `process.env.NODE_ENV === 'test'` it forces the
172+
# tests run only in English. The exception is the
173+
# `tests/translations/` suite which needs all languages to be set up.
174+
ENABLED_LANGUAGES: ${{ matrix.test-group == 'translations' && 'all' || '' }}
171175
run: npm test -- tests/${{ matrix.test-group }}/

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ ENV NODE_ENV production
7474
# Preferred port for server.js
7575
ENV PORT 4000
7676

77+
ENV ENABLED_LANGUAGES "en"
78+
7779
# This makes it possible to set `--build-arg BUILD_SHA=abc123`
7880
# and it then becomes available as an environment variable in the docker run.
7981
ARG BUILD_SHA
@@ -99,5 +101,9 @@ CMD ["node", "server.js"]
99101
# --------------------------------------------------------------------------------
100102
FROM preview as production
101103

104+
# Override what was set for previews
105+
# Make this match the default of `Object.keys(languages)` in lib/languages.js
106+
ENV ENABLED_LANGUAGES "en,zh,ja,es,pt,de,fr,ru,ko"
107+
102108
# Copy in all translations
103109
COPY --chown=node:node translations ./translations

azure-preview-env-template.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
{
6262
"name": "WEB_CONCURRENCY",
6363
"value": "1"
64+
},
65+
{
66+
"name": "ENABLED_LANGUAGES",
67+
"value": "en"
6468
}
6569
],
6670
"resources": {

contributing/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The [`script/bookmarklets`](../script/bookmarklets) directory contains some brow
4242

4343
### Enabling different languages
4444

45-
By default the local server won't run with all supported languages enabled. If you need to run the server with a particular language, you'll need to clone that language into your translations directory.
45+
By default the local server won't run with all supported languages enabled. If you need to run the server with a particular language, you can temporarily edit the `start` script in `package.json` and update the `ENABLED_LANGUAGES` variable. For example, to enable Japanese and Portuguese, you can set it to `ENABLED_LANGUAGES='en,ja,pt'` and then you need to restart the server for the change to take effect.
4646

4747
The supported language codes are defined in [lib/languages.js](../lib/languages.js).
4848

docker-compose.staging.tmpl.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
HYDRO_SECRET: ${HYDRO_SECRET}
1515
HAYSTACK_URL: ${HAYSTACK_URL}
1616
HEROKU_APP_NAME: ${HEROKU_APP_NAME}
17+
ENABLED_LANGUAGES: ${ENABLED_LANGUAGES}
1718
DEPLOYMENT_ENV: ${DEPLOYMENT_ENV}
1819
HEROKU_PRODUCTION_APP: true
1920
PORT: 4000

lib/languages.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import dotenv from 'dotenv'
66

77
import { TRANSLATIONS_ROOT } from './constants.js'
88
import path from 'path'
9-
import fs from 'fs/promises'
109

1110
dotenv.config()
1211

@@ -37,7 +36,7 @@ function getRoot(languageCode) {
3736

3837
// Languages in order of accept-language header frequency
3938
// 92BD1212-61B8-4E7A: Remove `wip: Boolean` for the public ship of ko, fr, de, ru
40-
let languages = {
39+
const languages = {
4140
en: {
4241
name: 'English',
4342
code: 'en',
@@ -116,18 +115,18 @@ let languages = {
116115
}
117116

118117
if (process.env.ENABLED_LANGUAGES) {
119-
languages = Object.fromEntries(
120-
process.env.ENABLED_LANGUAGES.split(',').map((code) => [code, languages[code]])
121-
)
122-
}
123-
124-
for (const language of Object.values(languages)) {
125-
if (language.code === 'en') continue
126-
try {
127-
await fs.readdir(language.dir)
128-
} catch (err) {
129-
delete languages[language.code]
118+
if (process.env.ENABLED_LANGUAGES.toLowerCase() !== 'all') {
119+
Object.keys(languages).forEach((code) => {
120+
if (!process.env.ENABLED_LANGUAGES.includes(code)) delete languages[code]
121+
})
122+
// This makes the translation health report not valid JSON
123+
// console.log(`ENABLED_LANGUAGES: ${process.env.ENABLED_LANGUAGES}`)
130124
}
125+
} else if (process.env.NODE_ENV === 'test') {
126+
// Unless explicitly set, when running tests default to just English
127+
Object.keys(languages).forEach((code) => {
128+
if (code !== 'en') delete languages[code]
129+
})
131130
}
132131

133132
export const languageKeys = Object.keys(languages)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
"scripts": {
181181
"browser-test": "cross-env BROWSER=1 NODE_OPTIONS=--experimental-vm-modules JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs jest tests/browser/browser.js",
182182
"build": "next build",
183-
"debug": "cross-env NODE_ENV=development nodemon --inspect server.js",
183+
"debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES=en nodemon --inspect server.js",
184184
"dev": "cross-env npm start",
185185
"index-test-fixtures": "node script/search/index-elasticsearch.js -l en -l ja -V ghae -V dotcom --index-prefix tests -- tests/content/fixtures/search-indexes",
186186
"lint": "eslint '**/*.{js,mjs,ts,tsx}'",
@@ -191,7 +191,7 @@
191191
"prevent-pushes-to-main": "node script/prevent-pushes-to-main.js",
192192
"rest-dev": "script/rest/update-files.js && npm run dev",
193193
"show-action-deps": "echo 'Action Dependencies:' && rg '^[\\s|-]*(uses:.*)$' .github -I -N --no-heading -r '$1$2' | sort | uniq | cut -c 7-",
194-
"start": "cross-env NODE_ENV=development nodemon server.js",
194+
"start": "cross-env NODE_ENV=development ENABLED_LANGUAGES=en nodemon server.js",
195195
"start-all-languages": "cross-env NODE_ENV=development nodemon server.js",
196196
"sync-search": "cross-env NODE_OPTIONS='--max_old_space_size=8192' start-server-and-test sync-search-server 4002 sync-search-indices",
197197
"sync-search-ghes-release": "cross-env GHES_RELEASE=1 start-server-and-test sync-search-server 4002 sync-search-indices",

script/search/index-elasticsearch.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ program
5353
.description('Creates Elasticsearch index from records')
5454
.option('-v, --verbose', 'Verbose outputs')
5555
.addOption(new Option('-V, --version [VERSION...]', 'Specific versions').choices(allVersionKeys))
56-
.addOption(new Option('-l, --language <LANGUAGE...>', 'Which languages to focus on'))
57-
.addOption(new Option('--not-language <LANGUAGE...>', 'Specific language to omit'))
56+
.addOption(
57+
new Option('-l, --language <LANGUAGE...>', 'Which languages to focus on').choices(languageKeys)
58+
)
59+
.addOption(
60+
new Option('--not-language <LANGUAGE...>', 'Specific language to omit').choices(languageKeys)
61+
)
5862
.option('-u, --elasticsearch-url <url>', 'If different from $ELASTICSEARCH_URL')
5963
.option('-p, --index-prefix <prefix>', 'Index string to put before index name')
6064
.argument('<source-directory>', 'where the indexable files are')
@@ -409,13 +413,9 @@ function escapeHTML(content) {
409413
}
410414

411415
async function loadRecords(indexName, sourceDirectory) {
412-
try {
413-
const filePath = path.join(sourceDirectory, `${indexName}-records.json`)
414-
const payload = await fs.readFile(filePath)
415-
return JSON.parse(payload)
416-
} catch (err) {
417-
throw new Error(`No records named ${indexName}-records.json, or not valid format.`)
418-
}
416+
const filePath = path.join(sourceDirectory, `${indexName}-records.json`)
417+
const payload = await fs.readFile(filePath)
418+
return JSON.parse(payload)
419419
}
420420

421421
function getSnowballLanguage(language) {

tests/translations/api-search.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@ import { jest, test, expect } from '@jest/globals'
22

33
import { describeIfElasticsearchURL } from '../helpers/conditional-runs.js'
44
import { get } from '../helpers/e2etest.js'
5-
import { languageKeys } from '../../lib/languages.js'
6-
7-
const langs = languageKeys.filter((lang) => lang !== 'en').filter((lang) => lang === 'ja') // temporary: only has japanese fixture so far
85

96
// This suite only runs if $ELASTICSEARCH_URL is set.
107
describeIfElasticsearchURL('search v1 middleware in non-English', () => {
118
jest.setTimeout(60 * 1000)
129

13-
test.each(langs)('basic search in %s', async (lang) => {
10+
test('basic search in Japanese', async () => {
1411
const sp = new URLSearchParams()
1512
// To see why this will work,
1613
// see tests/content/fixtures/search-indexes/github-docs-dotcom-en-records.json
1714
// which clearly has a record with the title "Foo"
1815
sp.set('query', 'foo')
19-
sp.set('language', lang)
16+
sp.set('language', 'ja')
2017
const res = await get('/api/search/v1?' + sp)
2118
expect(res.statusCode).toBe(200)
2219
const results = JSON.parse(res.text)

0 commit comments

Comments
 (0)