Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maintenance(www) value to check if i18n is enabled for this build #22956

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions www/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require(`path`)
require(`dotenv`).config({
path: `.env.${process.env.NODE_ENV}`,
})
const { langCodes } = require(`./src/utils/i18n`)
const { i18nEnabled, langCodes } = require(`./src/utils/i18n`)

const GA = {
identifier: `UA-93349937-5`,
Expand Down Expand Up @@ -53,12 +53,8 @@ if (process.env.AIRTABLE_API_KEY) {
})
}

// true if `env.LOCALES` has a defined list of languages
if (langCodes.length > 0) {
const naughtyFiles = [
`docs/docs/graphql-api.md`,
`docs/docs/data-fetching.md`,
]
if (i18nEnabled) {
const naughtyFiles = [`docs/docs/data-fetching.md`]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naughtyFiles should probably be named something else. These are the pages that use one-off MDX components, yeah? Even I wouldn't have known that if I hadn't just looked at issue #20795.

dynamicPlugins.push(
...langCodes.map(code => ({
resolve: `gatsby-source-git`,
Expand Down
3 changes: 2 additions & 1 deletion www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const child_process = require(`child_process`)
const startersRedirects = require(`./starter-redirects.json`)
const yaml = require(`js-yaml`)
const redirects = yaml.load(fs.readFileSync(`./redirects.yaml`))
const { i18nEnabled } = require(`./src/utils/i18n`)

const docs = require(`./src/utils/node/docs.js`)
const showcase = require(`./src/utils/node/showcase.js`)
Expand Down Expand Up @@ -41,7 +42,7 @@ exports.onCreateNode = helpers => {

exports.onPostBootstrap = () => {
// Compile language strings if locales are enabled
if (!!process.env.LOCALES) {
if (i18nEnabled) {
child_process.execSync(`yarn lingui:build`)
}
}
Expand Down
4 changes: 2 additions & 2 deletions www/src/components/I18nContext.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react"
import { defaultLang } from "../utils/i18n"
import { i18nEnabled, defaultLang } from "../utils/i18n"
import { I18nProvider as LinguiProvider } from "@lingui/react"

// Lingui doesn't give access to the locale, so we need our own provider
// to pass it down to child components
const LocaleContext = React.createContext(defaultLang)

export function I18nProvider({ locale = defaultLang, children }) {
const catalog = !!process.env.LOCALES
const catalog = i18nEnabled
? require(`../data/locales/${locale}/messages.js`)
: {}
return (
Expand Down
3 changes: 3 additions & 0 deletions www/src/utils/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function getLanguages(localeStr) {
const langs = getLanguages(process.env.LOCALES)
const langCodes = langs.map(lang => lang.code)

const i18nEnabled = langs.length > 0

function isDefaultLang(locale) {
return locale === defaultLang
}
Expand Down Expand Up @@ -78,6 +80,7 @@ function getLocaleAndBasePath(path, codes = langCodes) {
}

module.exports = {
i18nEnabled,
langCodes,
langs,
defaultLang,
Expand Down