Skip to content

Commit

Permalink
Create languages src directory (#41661)
Browse files Browse the repository at this point in the history
  • Loading branch information
heiskr authored Aug 30, 2023
1 parent df29357 commit 9bf3fc1
Show file tree
Hide file tree
Showing 108 changed files with 153 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/purge-fastly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
if: ${{ !inputs.nuke_all }}
env:
LANGUAGES: ${{ inputs.languages }}
run: .github/actions-scripts/purge-fastly-edge-cache-per-language.js
run: src/languages/scripts/purge-fastly-edge-cache-per-language.js
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
id: set-matrix
with:
script: |
// We only want to run the 'translations' suite when we know
// We only want to run the 'languages' suite when we know
// we're on the private docs-internal repo because only that
// one has ability to clone the remote (private) translations
// one has ability to clone the remote (private) languages
// repos.
// You can run multiple paths per suite as space-separated in `path`.
// Note that *if you add* to this, remember to also add that
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
{ name: 'search', path: 'src/search/tests', },
{ name: 'shielding', path: 'src/shielding/tests', },
context.payload.repository.full_name === 'github/docs-internal' &&
{ name: 'translations', path: 'tests/translations', },
{ name: 'languages', path: 'src/languages/tests', },
{ name: 'unit', path: 'tests/unit', },
// { name: 'tools', path: 'src/tools/tests', }
{ name: 'webhooks', path: 'src/webhooks/tests', },
Expand All @@ -88,7 +88,7 @@ jobs:
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab

- uses: ./.github/actions/setup-elasticsearch
if: ${{ matrix.name == 'search' || matrix.name == 'translations' }}
if: ${{ matrix.name == 'search' || matrix.name == 'languages' }}

- uses: ./.github/actions/node-npm-setup

Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
tests/fixtures/data
- name: Clone all translations
if: ${{ matrix.name == 'translations' }}
if: ${{ matrix.name == 'languages' }}
uses: ./.github/actions/clone-translations
with:
token: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
- name: Index fixtures into the local Elasticsearch
# For the sake of saving time, only run this step if the group
# is one that will run tests against an Elasticsearch on localhost.
if: ${{ matrix.name == 'search' || matrix.name == 'translations' }}
if: ${{ matrix.name == 'search' || matrix.name == 'languages' }}
run: npm run index-test-fixtures

- name: Run tests
Expand All @@ -178,8 +178,8 @@ jobs:
CHANGELOG_CACHE_FILE_PATH: tests/fixtures/changelog-feed.json
# By default, when `process.env.NODE_ENV === 'test'` it forces the
# tests run only in English. The exception is the
# `tests/translations/` suite which needs all languages to be set up.
ENABLED_LANGUAGES: ${{ matrix.name == 'translations' && 'all' || '' }}
# `languages` suite which needs all languages to be set up.
ENABLED_LANGUAGES: ${{ matrix.name == 'languages' && 'all' || '' }}
ROOT: ${{ (matrix.name == 'rendering-fixtures' || matrix.name == 'pageinfo' || matrix.name == 'landings' ) && 'tests/fixtures' || '' }}
TRANSLATIONS_FIXTURE_ROOT: ${{ (matrix.name == 'rendering-fixtures' || matrix.name == 'pageinfo') && 'tests/fixtures/translations' || '' }}
run: npm test -- ${{ matrix.path }}/
2 changes: 1 addition & 1 deletion components/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SupportSection } from 'components/page-footer/SupportSection'
import { DeprecationBanner } from 'components/page-header/DeprecationBanner'
import { RestBanner } from 'src/rest/components/RestBanner'
import { useMainContext } from 'components/context/MainContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { Breadcrumbs } from 'components/page-header/Breadcrumbs'

const MINIMAL_RENDER = Boolean(JSON.parse(process.env.MINIMAL_RENDER || 'false'))
Expand Down
2 changes: 1 addition & 1 deletion components/article/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { LearningTrackCard } from 'src/learning-track/components/article/Learnin
import { RestRedirect } from 'src/rest/components/RestRedirect'
import { Breadcrumbs } from 'components/page-header/Breadcrumbs'
import { Link } from 'components/Link'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { LinkPreviewPopover } from 'components/LinkPreviewPopover'

const ClientSideRefresh = dynamic(() => import('components/ClientSideRefresh'), {
Expand Down
2 changes: 1 addition & 1 deletion components/page-footer/Contribution.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GitPullRequestIcon } from '@primer/octicons-react'

import { useMainContext } from 'components/context/MainContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'

export const Contribution = () => {
const { relativePath } = useMainContext()
Expand Down
2 changes: 1 addition & 1 deletion components/page-footer/LegalFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
import { LinkExternalIcon } from '@primer/octicons-react'
import cx from 'classnames'
import { useTranslation } from '../hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'

export const LegalFooter = () => {
const router = useRouter()
Expand Down
2 changes: 1 addition & 1 deletion components/page-footer/Support.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PeopleIcon, CommentDiscussionIcon } from '@primer/octicons-react'

import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { useMainContext } from 'components/context/MainContext'

export const Support = () => {
Expand Down
2 changes: 1 addition & 1 deletion components/page-footer/SupportSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Support } from 'components/page-footer/Support'
import { useMainContext } from 'components/context/MainContext'
import { useVersion } from 'components/hooks/useVersion'
import { useRouter } from 'next/router'
import { useTranslation } from '../hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'

export const SupportSection = () => {
const { currentVersion } = useVersion()
Expand Down
4 changes: 2 additions & 2 deletions components/page-header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { DEFAULT_VERSION, useVersion } from 'components/hooks/useVersion'
import { Link } from 'components/Link'
import { useMainContext } from 'components/context/MainContext'
import { useHasAccount } from 'components/hooks/useHasAccount'
import { LanguagePicker } from './LanguagePicker'
import { LanguagePicker } from 'src/languages/components/LanguagePicker'
import { HeaderNotifications } from 'components/page-header/HeaderNotifications'
import { ApiVersionPicker } from 'src/rest/components/ApiVersionPicker'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { Search } from 'src/search/components/Search'
import { Breadcrumbs } from 'components/page-header/Breadcrumbs'
import { VersionPicker } from 'components/page-header/VersionPicker'
Expand Down
6 changes: 3 additions & 3 deletions components/page-header/HeaderNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useRouter } from 'next/router'
import cx from 'classnames'
import { XIcon } from '@primer/octicons-react'

import { useLanguages } from 'components/context/LanguagesContext'
import { useLanguages } from 'src/languages/components/LanguagesContext'
import { useMainContext } from 'components/context/MainContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { ExcludesNull } from 'components/lib/ExcludesNull'
import { useVersion } from 'components/hooks/useVersion'
import { useUserLanguage } from 'components/hooks/useUserLanguage'
import { useUserLanguage } from 'src/languages/components/useUserLanguage'
import styles from './HeaderNotifications.module.scss'

enum NotificationType {
Expand Down
2 changes: 1 addition & 1 deletion components/page-header/VersionPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ArrowRightIcon, InfoIcon } from '@primer/octicons-react'

import { useMainContext } from 'components/context/MainContext'
import { DEFAULT_VERSION, useVersion } from 'components/hooks/useVersion'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { Picker } from 'src/tools/components/Picker'

import styles from './VersionPicker.module.scss'
Expand Down
2 changes: 1 addition & 1 deletion components/ui/MiniTocs/MiniTocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'
import cx from 'classnames'

import type { MiniTocItem } from 'components/context/ArticleContext'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'

import styles from './Minitocs.module.scss'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cx from 'classnames'

import styles from './PermissionsStatement.module.scss'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'

type Props = {
permissions: string
Expand Down
2 changes: 1 addition & 1 deletion contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The [`script/bookmarklets`](../script/bookmarklets) directory contains some brow

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.

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

## Site structure

Expand Down
2 changes: 1 addition & 1 deletion lib/get-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import yaml from 'js-yaml'
import matter from 'gray-matter'
import { merge, get } from 'lodash-es'

import languages from './languages.js'
import languages from '#src/languages/lib/languages.js'
import { correctTranslatedContentStrings } from './correct-translation-content.js'

// If you run `export DEBUG_JIT_DATA_READS=true` in your terminal,
Expand Down
2 changes: 1 addition & 1 deletion lib/page-data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'

import languages from './languages.js'
import languages from '#src/languages/lib/languages.js'
import { allVersions } from './all-versions.js'
import createTree from './create-tree.js'
import nonEnterpriseDefaultVersion from './non-enterprise-default-version.js'
Expand Down
2 changes: 1 addition & 1 deletion lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import getEnglishHeadings from './get-english-headings.js'
import getTocItems from './get-toc-items.js'
import pathUtils from './path-utils.js'
import Permalink from './permalink.js'
import languages from './languages.js'
import languages from '#src/languages/lib/languages.js'
import { renderContent } from '#src/content-render/index.js'
import processLearningTracks from '#src/learning-track/lib/process-learning-tracks.js'
import { productMap } from './all-products.js'
Expand Down
2 changes: 1 addition & 1 deletion middleware/archived-enterprise-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { setFastlySurrogateKey, SURROGATE_ENUMS } from './set-fastly-surrogate-k
import got from 'got'
import { readCompressedJsonFileFallbackLazily } from '../lib/read-json-file.js'
import { archivedCacheControl, languageCacheControl } from './cache-control.js'
import { pathLanguagePrefixed, languagePrefixPathRegex } from '../lib/languages.js'
import { pathLanguagePrefixed, languagePrefixPathRegex } from '#src/languages/lib/languages.js'
import getRedirect, { splitPathByLanguage } from '../src/redirects/lib/get-redirect.js'
import getRemoteJSON from './get-remote-json.js'

Expand Down
2 changes: 1 addition & 1 deletion middleware/context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import languages from '../lib/languages.js'
import languages from '#src/languages/lib/languages.js'
import enterpriseServerReleases from '../lib/enterprise-server-releases.js'
import { allVersions } from '../lib/all-versions.js'
import { productMap } from '../lib/all-products.js'
Expand Down
2 changes: 1 addition & 1 deletion middleware/contextualizers/product-groups.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getProductGroups } from '../../lib/get-product-groups.js'
import warmServer from '../../lib/warm-server.js'
import { languageKeys } from '../../lib/languages.js'
import { languageKeys } from '#src/languages/lib/languages.js'
import { allVersionKeys } from '../../lib/all-versions.js'

const isHomepage = (path) => {
Expand Down
2 changes: 1 addition & 1 deletion middleware/find-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { existsSync } from 'fs'

import { ROOT } from '../lib/constants.js'
import Page from '../lib/page.js'
import { languagePrefixPathRegex } from '../lib/languages.js'
import { languagePrefixPathRegex } from '#src/languages/lib/languages.js'

const englishPrefixRegex = /^\/en(\/|$)/
const CONTENT_ROOT = path.join(ROOT, 'content')
Expand Down
2 changes: 1 addition & 1 deletion middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './set-fastly-surrogate-key.js'
import handleErrors from '#src/observability/middleware/handle-errors.js'
import handleNextDataPath from './handle-next-data-path.js'
import detectLanguage from './detect-language.js'
import detectLanguage from '#src/languages/middleware/detect-language.js'
import reloadTree from './reload-tree.js'
import context from './context.js'
import shortVersions from './contextualizers/short-versions.js'
Expand Down
2 changes: 1 addition & 1 deletion middleware/reload-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import path from 'path'

import languages, { languageKeys } from '../lib/languages.js'
import languages, { languageKeys } from '#src/languages/lib/languages.js'
import createTree from '../lib/create-tree.js'
import warmServer from '../lib/warm-server.js'
import { loadSiteTree, loadPages, loadPageMap } from '../lib/page-data.js'
Expand Down
2 changes: 1 addition & 1 deletion middleware/render-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FailBot from '#src/observability/lib/failbot.js'
import patterns from '../lib/patterns.js'
import getMiniTocItems from '../lib/get-mini-toc-items.js'
import Page from '../lib/page.js'
import { pathLanguagePrefixed } from '../lib/languages.js'
import { pathLanguagePrefixed } from '#src/languages/lib/languages.js'
import statsd from '#src/observability/lib/statsd.js'
import { allVersions } from '../lib/all-versions.js'
import { isConnectionDropped } from './halt-on-dropped-connection.js'
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import path from 'path'

import frontmatter from 'gray-matter'
import { languageKeys } from './lib/languages.js'
import { languageKeys } from '#src/languages/lib/languages.js'
import { ROOT } from './lib/constants.js'

const homepage = path.posix.join(ROOT, 'content/index.md')
Expand Down
2 changes: 1 addition & 1 deletion script/purge-fastly-by-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import fs from 'fs/promises'
import path from 'path'
import { program } from 'commander'
import { execSync } from 'child_process'
import libLanguages from '../lib/languages.js'
import libLanguages from '#src/languages/lib/languages.js'
import { getPathWithoutLanguage } from '../lib/path-utils.js'

const languageCodes = Object.keys(libLanguages)
Expand Down
2 changes: 1 addition & 1 deletion src/assets/scripts/find-orphaned-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { program } from 'commander'
import walk from 'walk-sync'

import walkFiles from '../../../script/helpers/walk-files.js'
import languages from '../../../lib/languages.js'
import languages from '#src/languages/lib/languages.js'

const EXCEPTIONS = new Set([
'assets/images/site/favicon.ico',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cx from 'classnames'

import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { ParameterRow } from './ParameterRow'
import type { ChildParameter } from './types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cx from 'classnames'

import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { ChildBodyParametersRows } from './ChildBodyParametersRows'
import type { ChildParameter } from './types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cx from 'classnames'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'

import { ParameterRow } from './ParameterRow'
import { BodyParameter, ChildParameter, Parameter } from './types'
Expand Down
2 changes: 1 addition & 1 deletion src/codeql-cli/scripts/convert-markdown-for-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { visitParents } from 'unist-util-visit-parents'
import { visit, SKIP } from 'unist-util-visit'
import { remove } from 'unist-util-remove'

import { languageKeys } from '../../../lib/languages.js'
import { languageKeys } from '#src/languages/lib/languages.js'
import { MARKDOWN_OPTIONS } from '../../content-linter/lib/helpers/unified-formatter-options.js'

const { targetDirectory, removeKeywords } = JSON.parse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { filterTokens } from 'markdownlint-rule-helpers'

import { addFixErrorDetail, getRange } from '../helpers/utils.js'
import { languageKeys } from '../../../../lib/languages.js'
import { languageKeys } from '#src/languages/lib/languages.js'

export const internalLinksLang = {
names: ['GHD005', 'internal-links-lang'],
Expand Down
2 changes: 1 addition & 1 deletion src/content-linter/tests/lint-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import semver from 'semver'
import { jest } from '@jest/globals'

import { frontmatter, deprecatedProperties } from '../../../lib/frontmatter.js'
import languages from '../../../lib/languages.js'
import languages from '#src/languages/lib/languages.js'
import releaseNotesSchema from '../lib/release-notes-schema.js'
import learningTracksSchema from '../lib/learning-tracks-schema.js'
import { liquid } from '#src/content-render/index.js'
Expand Down
2 changes: 1 addition & 1 deletion src/content-render/tests/data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterAll, beforeAll, expect, describe, it } from '@jest/globals'

import Page from '../../../lib/page.js'
import languages from '../../../lib/languages.js'
import languages from '#src/languages/lib/languages.js'
import nonEnterpriseDefaultVersion from '../../../lib/non-enterprise-default-version.js'
import { DataDirectory } from '../../../tests/helpers/data-directory.js'

Expand Down
2 changes: 1 addition & 1 deletion src/content-render/tests/liquid-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterAll, jest, beforeAll, expect } from '@jest/globals'
import { liquid } from '#src/content-render/index.js'
import languages from '../../../lib/languages.js'
import languages from '#src/languages/lib/languages.js'
import { DataDirectory } from '../../../tests/helpers/data-directory.js'

describe('liquid helper tags', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/early-access/tests/early-access-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, jest, test } from '@jest/globals'
import { get, getDOM } from '../../../tests/helpers/e2etest.js'

import { describeIfDocsEarlyAccess } from '../../../tests/helpers/conditional-runs.js'
import languages from '../../../lib/languages.js'
import languages from '#src/languages/lib/languages.js'

const VALID_EARLY_ACCESS_URI = '/early-access/github/save-time-with-slash-commands'

Expand Down
2 changes: 1 addition & 1 deletion src/events/components/Survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useRef, useEffect } from 'react'
import cx from 'classnames'
import { useRouter } from 'next/router'
import { ThumbsdownIcon, ThumbsupIcon } from '@primer/octicons-react'
import { useTranslation } from 'components/hooks/useTranslation'
import { useTranslation } from 'src/languages/components/useTranslation'
import { Link } from 'components/Link'
import { sendEvent, EventType } from 'src/events/components/events'

Expand Down
2 changes: 1 addition & 1 deletion src/events/lib/schema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { languageKeys } from '../../../lib/languages.js'
import { languageKeys } from '#src/languages/lib/languages.js'
import { allVersionKeys } from '../../../lib/all-versions.js'
import { productIds } from '../../../lib/all-products.js'
import { allTools } from '#src/tools/lib/all-tools.js'
Expand Down
2 changes: 1 addition & 1 deletion src/frame/pages/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
LanguagesContext,
LanguagesContextT,
LanguageItem,
} from 'components/context/LanguagesContext'
} from 'src/languages/components/LanguagesContext'
import { useTheme } from 'components/hooks/useTheme'

type MyAppProps = AppProps & {
Expand Down
Loading

0 comments on commit 9bf3fc1

Please sign in to comment.