Skip to content

Commit b70cc43

Browse files
authored
Merge pull request #23204 from github/repo-sync
repo sync
2 parents 91396e5 + cdf1123 commit b70cc43

File tree

10 files changed

+30
-46
lines changed

10 files changed

+30
-46
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ 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
9489
run: node .github/actions-scripts/rendered-content-link-checker.js
9590

9691
- name: Upload artifact(s)

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,4 @@ 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' || '' }}
175171
run: npm test -- tests/${{ matrix.test-group }}/

Dockerfile

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

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

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-
108102
# Copy in all translations
109103
COPY --chown=node:node translations ./translations

azure-preview-env-template.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@
6161
{
6262
"name": "WEB_CONCURRENCY",
6363
"value": "1"
64-
},
65-
{
66-
"name": "ENABLED_LANGUAGES",
67-
"value": "en"
6864
}
6965
],
7066
"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 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.
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.
4646

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

docker-compose.staging.tmpl.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ services:
1414
HYDRO_SECRET: ${HYDRO_SECRET}
1515
HAYSTACK_URL: ${HAYSTACK_URL}
1616
HEROKU_APP_NAME: ${HEROKU_APP_NAME}
17-
ENABLED_LANGUAGES: ${ENABLED_LANGUAGES}
1817
DEPLOYMENT_ENV: ${DEPLOYMENT_ENV}
1918
HEROKU_PRODUCTION_APP: true
2019
PORT: 4000

lib/languages.js

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

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

1011
dotenv.config()
1112

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

3738
// Languages in order of accept-language header frequency
3839
// 92BD1212-61B8-4E7A: Remove `wip: Boolean` for the public ship of ko, fr, de, ru
39-
const languages = {
40+
let languages = {
4041
en: {
4142
name: 'English',
4243
code: 'en',
@@ -115,18 +116,18 @@ const languages = {
115116
}
116117

117118
if (process.env.ENABLED_LANGUAGES) {
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}`)
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]
124130
}
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-
})
130131
}
131132

132133
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 ENABLED_LANGUAGES=en nodemon --inspect server.js",
183+
"debug": "cross-env NODE_ENV=development 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 ENABLED_LANGUAGES=en nodemon server.js",
194+
"start": "cross-env NODE_ENV=development 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,12 +53,8 @@ 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(
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-
)
56+
.addOption(new Option('-l, --language <LANGUAGE...>', 'Which languages to focus on'))
57+
.addOption(new Option('--not-language <LANGUAGE...>', 'Specific language to omit'))
6258
.option('-u, --elasticsearch-url <url>', 'If different from $ELASTICSEARCH_URL')
6359
.option('-p, --index-prefix <prefix>', 'Index string to put before index name')
6460
.argument('<source-directory>', 'where the indexable files are')
@@ -413,9 +409,13 @@ function escapeHTML(content) {
413409
}
414410

415411
async function loadRecords(indexName, sourceDirectory) {
416-
const filePath = path.join(sourceDirectory, `${indexName}-records.json`)
417-
const payload = await fs.readFile(filePath)
418-
return JSON.parse(payload)
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+
}
419419
}
420420

421421
function getSnowballLanguage(language) {

tests/translations/api-search.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ 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
58

69
// This suite only runs if $ELASTICSEARCH_URL is set.
710
describeIfElasticsearchURL('search v1 middleware in non-English', () => {
811
jest.setTimeout(60 * 1000)
912

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

0 commit comments

Comments
 (0)