Skip to content

Commit dbc72a4

Browse files
authored
Merge pull request #7070 from ethereum/dev
Deploy v4.8.0
2 parents 08ee8f3 + e3671bc commit dbc72a4

File tree

88 files changed

+960
-506
lines changed

Some content is hidden

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

88 files changed

+960
-506
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8133,6 +8133,15 @@
81338133
"contributions": [
81348134
"code"
81358135
]
8136+
},
8137+
{
8138+
"login": "smejak",
8139+
"name": "Jakub Smékal",
8140+
"avatar_url": "https://avatars.githubusercontent.com/u/20759274?v=4",
8141+
"profile": "https://github.com/smejak",
8142+
"contributions": [
8143+
"doc"
8144+
]
81368145
}
81378146
],
81388147
"contributorsPerLine": 7,

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
13041304
<td align="center"><a href="http://[email protected]"><img src="https://avatars.githubusercontent.com/u/40423181?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sandy</b></sub></a><br /><a href="https://github.com/ethereum/ethereum-org-website/commits?author=zyjblockchain" title="Documentation">📖</a></td>
13051305
<td align="center"><a href="https://github.com/NachoRoizman"><img src="https://avatars.githubusercontent.com/u/107893772?v=4?s=100" width="100px;" alt=""/><br /><sub><b>NachoRoizman</b></sub></a><br /><a href="https://github.com/ethereum/ethereum-org-website/commits?author=NachoRoizman" title="Documentation">📖</a></td>
13061306
<td align="center"><a href="https://linkedin.com/in/miragaya-ivan"><img src="https://avatars.githubusercontent.com/u/72365253?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Iván Miragaya</b></sub></a><br /><a href="https://github.com/ethereum/ethereum-org-website/commits?author=M-Ivan" title="Code">💻</a></td>
1307+
<td align="center"><a href="https://github.com/smejak"><img src="https://avatars.githubusercontent.com/u/20759274?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jakub Smékal</b></sub></a><br /><a href="https://github.com/ethereum/ethereum-org-website/commits?author=smejak" title="Documentation">📖</a></td>
13071308
</tr>
13081309
</table>
13091310

docs/best-practices.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Markdown will be translated as whole pages of content, so no specific action is
5252

5353
- _tl;dr Each individual JSON entry should be a complete phrase by itself_
5454

55-
- This is done using the `Translation` component. However there is an alternative method for regular JS: `gatsby-plugin-intl` with `/src/utils/translations.ts`
55+
- This is done using the `Translation` component. However there is an alternative method for regular JS: `gatsby-theme-i18n` with `/src/utils/translations.ts`
5656

5757
- **Method one: `<Translation />` component (preferred if only needed in JSX)**
5858

@@ -66,7 +66,7 @@ Markdown will be translated as whole pages of content, so no specific action is
6666
- **Method two: `translateMessageId()`**
6767

6868
```tsx
69-
import { useIntl } from "gatsby-plugin-intl"
69+
import { useIntl } from "react-intl"
7070
import { translateMessageId } from "src/utils/translations"
7171
7272
// Utilize anywhere in JS using

gatsby-browser.tsx

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
import React from "react"
8-
import Layout from "./src/components/Layout"
8+
import browserLang from "browser-lang"
9+
import { withPrefix, GatsbyBrowser } from "gatsby"
910

1011
import Prism from "prism-react-renderer/prism"
1112
;(typeof global !== "undefined" ? global : window).Prism = Prism
@@ -15,12 +16,52 @@ import "@formatjs/intl-locale/polyfill"
1516
import "@formatjs/intl-numberformat/polyfill"
1617
import "@formatjs/intl-numberformat/locale-data/en"
1718

19+
import Layout from "./src/components/Layout"
20+
import {
21+
supportedLanguages,
22+
defaultLanguage,
23+
isLang,
24+
} from "./src/utils/languages"
25+
import { Context } from "./src/types"
26+
1827
// Default languages included:
1928
// https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js
2029
require("prismjs/components/prism-solidity")
2130

2231
// Prevents <Layout/> from unmounting on page transitions
2332
// https://www.gatsbyjs.com/docs/layout-components/#how-to-prevent-layout-components-from-unmounting
24-
export const wrapPageElement = ({ element, props }) => (
25-
<Layout {...props}>{element}</Layout>
26-
)
33+
export const wrapPageElement: GatsbyBrowser<
34+
any,
35+
Context
36+
>["wrapPageElement"] = ({ element, props }) => {
37+
const { location, pageContext } = props
38+
const { pathname, search } = location
39+
const { originalPath } = pageContext
40+
41+
const [, pathLocale] = pathname.split("/")
42+
43+
// client side redirect on paths that don't have a locale in them. Most useful
44+
// on dev env where we don't have server redirects
45+
if (!isLang(pathLocale)) {
46+
let detected =
47+
window.localStorage.getItem("eth-org-language") ||
48+
browserLang({
49+
languages: supportedLanguages,
50+
fallback: defaultLanguage,
51+
})
52+
53+
if (!isLang(detected)) {
54+
detected = defaultLanguage
55+
}
56+
57+
const queryParams = search || ""
58+
const newUrl = withPrefix(`/${detected}${originalPath}${queryParams}`)
59+
window.localStorage.setItem("eth-org-language", detected)
60+
window.location.replace(newUrl)
61+
62+
// can't return null here, must return an element
63+
return <div />
64+
}
65+
66+
return <Layout {...props}>{element}</Layout>
67+
}

gatsby-config.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
ignoreLanguages,
1010
} from "./src/utils/languages"
1111

12+
import { IS_PREVIEW } from "./src/utils/env"
13+
1214
const siteUrl = `https://ethereum.org`
1315

1416
const ignoreContent = (process.env.IGNORE_CONTENT || "")
1517
.split(",")
1618
.filter(Boolean)
1719

18-
const isPreviewDeploy = process.env.IS_PREVIEW_DEPLOY === "true"
19-
2020
const ignoreTranslations = ignoreLanguages.map(
2121
(lang) => `**/translations\/${lang}`
2222
)
@@ -37,17 +37,20 @@ const config: GatsbyConfig = {
3737
plugins: [
3838
// i18n support
3939
{
40-
resolve: `gatsby-plugin-intl`,
40+
resolve: `gatsby-theme-i18n`,
41+
options: {
42+
defaultLang: defaultLanguage,
43+
prefixDefault: true,
44+
locales: supportedLanguages.length
45+
? supportedLanguages.join(" ")
46+
: null,
47+
configPath: path.resolve(`./i18n/config.json`),
48+
},
49+
},
50+
{
51+
resolve: `gatsby-theme-i18n-react-intl`,
4152
options: {
42-
// language JSON resource path
43-
path: path.resolve(`src/intl`),
44-
// supported language
45-
languages: supportedLanguages,
46-
// language file path
47-
defaultLanguage,
48-
// redirect to `/${lang}/` when connecting to `/`
49-
// based on user's browser language preference
50-
redirect: true,
53+
defaultLocale: `./src/intl/en.json`,
5154
},
5255
},
5356
// Web app manifest
@@ -239,7 +242,7 @@ const config: GatsbyConfig = {
239242

240243
// Avoid loading Matomo in preview deploys since NODE_ENV is `production` in
241244
// there and it will send testing data as production otherwise
242-
if (!isPreviewDeploy) {
245+
if (!IS_PREVIEW) {
243246
config.plugins = [
244247
...(config.plugins || []),
245248
// Matomo analtyics

gatsby-node.ts

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
defaultLanguage,
1919
Lang,
2020
} from "./src/utils/languages"
21-
import getMessages from "./src/utils/getMessages"
21+
import { IS_DEV } from "./src/utils/env"
2222
import redirects from "./redirects.json"
2323

2424
const exec = util.promisify(child_process.exec)
@@ -153,9 +153,6 @@ export const onCreateNode: GatsbyNode<{
153153

154154
if (slug.includes("/translations/")) {
155155
slug = slug.replace("/translations", "")
156-
const split = slug.split("/")
157-
split.splice(1, 1)
158-
159156
isOutdated = await checkIsMdxOutdated(node.fileAbsolutePath)
160157
} else {
161158
slug = `/${defaultLanguage}${slug}`
@@ -193,6 +190,7 @@ export const createPages: GatsbyNode<any, Context>["createPages"] = async ({
193190
}) => {
194191
const { createPage, createRedirect } = actions
195192

193+
// server side redirects
196194
redirects.forEach((redirect) => {
197195
createRedirect({
198196
...redirect,
@@ -271,27 +269,22 @@ export const createPages: GatsbyNode<any, Context>["createPages"] = async ({
271269
const splitSlug = slug.split("/")
272270
splitSlug.splice(1, 1, lang)
273271
const langSlug = splitSlug.join("/")
274-
createPage({
272+
createPage<Context>({
275273
path: langSlug,
276274
component: path.resolve(`src/templates/${template}.tsx`),
277275
context: {
276+
language: lang,
278277
slug: langSlug,
279278
ignoreTranslationBanner: isLegal,
280279
isLegal: isLegal,
281280
isOutdated: false,
282281
isContentEnglish: true,
283-
relativePath: relativePath, // Use English path for template MDX query
284-
// Create `intl` object so `gatsby-plugin-intl` will skip
285-
// generating language variations for this page
286-
intl: {
287-
language: lang,
288-
defaultLanguage,
289-
languages: supportedLanguages,
290-
messages: getMessages("./src/intl/", lang),
291-
routed: true,
292-
originalPath: slug.substr(3),
293-
redirect: false,
294-
},
282+
relativePath, // Use English path for template MDX query
283+
// gatsby i18n theme context
284+
locale: lang,
285+
hrefLang: lang,
286+
originalPath: langSlug.slice(3),
287+
dateFormat: "MM/DD/YYYY",
295288
},
296289
})
297290
}
@@ -305,18 +298,13 @@ export const createPages: GatsbyNode<any, Context>["createPages"] = async ({
305298
language,
306299
slug,
307300
isOutdated: !!node.fields.isOutdated,
308-
relativePath: relativePath,
309-
// Create `intl` object so `gatsby-plugin-intl` will skip
310-
// generating language variations for this page
311-
intl: {
312-
language,
313-
defaultLanguage,
314-
languages: supportedLanguages,
315-
messages: getMessages("./src/intl/", language),
316-
routed: true,
317-
originalPath: slug.substr(3),
318-
redirect: false,
319-
},
301+
isDefaultLang: language === defaultLanguage,
302+
relativePath,
303+
// gatsby i18n theme context
304+
locale: language,
305+
hrefLang: language,
306+
originalPath: slug.slice(3),
307+
dateFormat: "MM/DD/YYYY",
320308
},
321309
})
322310
})
@@ -338,22 +326,22 @@ export const createPages: GatsbyNode<any, Context>["createPages"] = async ({
338326
page,
339327
lang
340328
)
341-
createPage({
342-
path: `/${lang}/${page}/`,
329+
const originalPath = `/${page}/`
330+
const slug = `/${lang}${originalPath}`
331+
332+
createPage<Context>({
333+
path: slug,
343334
component: path.resolve(`src/pages-conditional/${page}.tsx`),
344335
context: {
345-
slug: `/${lang}/${page}/`,
346-
intl: {
347-
language: lang,
348-
languages: supportedLanguages,
349-
defaultLanguage,
350-
messages: getMessages("./src/intl/", lang),
351-
routed: true,
352-
originalPath: `/${page}/`,
353-
redirect: false,
354-
},
336+
language: lang,
337+
slug,
355338
isContentEnglish,
356339
isOutdated,
340+
// gatsby i18n theme context
341+
locale: lang,
342+
hrefLang: lang,
343+
originalPath,
344+
dateFormat: "MM/DD/YYYY",
357345
},
358346
})
359347
}
@@ -370,13 +358,21 @@ export const onCreatePage: GatsbyNode<any, Context>["onCreatePage"] = async ({
370358
}) => {
371359
const { createPage, deletePage } = actions
372360

373-
const isTranslated = page.context.language !== defaultLanguage
361+
// create routes without the lang prefix e.g. `/{path}` as our i18n plugin
362+
// only creates `/{lang}/{path}` routes. This is useful on dev env to avoid
363+
// getting a 404 since we don't have server side redirects
364+
if (IS_DEV && page.path.startsWith(`/${defaultLanguage}`)) {
365+
const path = page.path.slice(3)
366+
createPage({ ...page, path })
367+
}
368+
369+
const isTranslated = page.context.locale !== defaultLanguage
374370
const hasNoContext = page.context.isOutdated === undefined
375371

376372
if (isTranslated && hasNoContext) {
377373
const { isOutdated, isContentEnglish } = await checkIsPageOutdated(
378-
page.context.intl.originalPath,
379-
page.context.language
374+
page.context.originalPath,
375+
page.context.locale
380376
)
381377
deletePage(page)
382378
createPage<Context>({

gatsby-ssr.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import type { GatsbySSR } from "gatsby"
1010

1111
import Layout from "./src/components/Layout"
1212

13+
import { Context } from "./src/types"
14+
1315
// Prevents <Layout/> from unmounting on page transitions
1416
// https://www.gatsbyjs.com/docs/layout-components/#how-to-prevent-layout-components-from-unmounting
15-
export const wrapPageElement: GatsbySSR["wrapPageElement"] = ({
17+
export const wrapPageElement: GatsbySSR<any, Context>["wrapPageElement"] = ({
1618
element,
1719
props,
1820
}) => {

0 commit comments

Comments
 (0)