Skip to content

Commit 8a18427

Browse files
author
soheil
committed
Merge branch 'dev' into feat/beacon-chain-actions-to-chakra
2 parents 218294d + 0949d36 commit 8a18427

File tree

115 files changed

+3434
-2442
lines changed

Some content is hidden

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

115 files changed

+3434
-2442
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9708,6 +9708,16 @@
97089708
"contributions": [
97099709
"doc"
97109710
]
9711+
},
9712+
{
9713+
"login": "Olshansk",
9714+
"name": "Daniel Olshansky",
9715+
"avatar_url": "https://avatars.githubusercontent.com/u/1892194?v=4",
9716+
"profile": "http://olshansky.info",
9717+
"contributions": [
9718+
"doc",
9719+
"ideas"
9720+
]
97119721
}
97129722
],
97139723
"contributorsPerLine": 7,

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ yarn-error.log
7676
src/data/contributors.json
7777
# These files are generated by `yarn merge-translations` command
7878
src/intl/*.json
79-
i18n/locales
8079
# Auto generated code when gatsby build the site
8180
src/gatsby-types.d.ts
8281

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
15251525
<td align="center"><a href="https://github.com/mossow"><img src="https://avatars.githubusercontent.com/u/9072132?v=4?s=100" width="100px;" alt="mossow"/><br /><sub><b>mossow</b></sub></a><br /><a href="https://github.com/ethereum/ethereum-org-website/commits?author=mossow" title="Documentation">📖</a></td>
15261526
<td align="center"><a href="https://github.com/OpenWJY"><img src="https://avatars.githubusercontent.com/u/29328336?v=4?s=100" width="100px;" alt="yujingwei"/><br /><sub><b>yujingwei</b></sub></a><br /><a href="https://github.com/ethereum/ethereum-org-website/commits?author=OpenWJY" title="Documentation">📖</a></td>
15271527
</tr>
1528+
<tr>
1529+
<td align="center"><a href="http://olshansky.info"><img src="https://avatars.githubusercontent.com/u/1892194?v=4?s=100" width="100px;" alt="Daniel Olshansky"/><br /><sub><b>Daniel Olshansky</b></sub></a><br /><a href="https://github.com/ethereum/ethereum-org-website/commits?author=Olshansk" title="Documentation">📖</a> <a href="#ideas-Olshansk" title="Ideas, Planning, & Feedback">🤔</a></td>
1530+
</tr>
15281531
</tbody>
15291532
</table>
15301533

docs/best-practices.md

Lines changed: 6 additions & 7 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-theme-i18n` with `/src/utils/translations.ts`
55+
- This is done using the `Translation` component. However there is an alternative method for regular JS: using the `t` function from `gatsby-plugin-react-i18next`
5656

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

@@ -63,19 +63,18 @@ Markdown will be translated as whole pages of content, so no specific action is
6363
;<Translation id="language-json-key" />
6464
```
6565

66-
- **Method two: `translateMessageId()`**
66+
- **Method two: `t()`**
6767

6868
```tsx
69-
import { useIntl } from "react-intl"
70-
import { translateMessageId } from "src/utils/translations"
69+
import { useTranslation } from "gatsby-plugin-react-i18next"
7170
7271
// Utilize anywhere in JS using
73-
const intl = useIntl()
74-
translateMessageId("language-json-key", intl)
72+
const { t } = useTranslation()
73+
t("language-json-key")
7574
```
7675

7776
```tsx
78-
const siteTitle = translateMessageId("site-title", intl)
77+
const siteTitle = t("site-title")
7978
```
8079

8180
## React Hooks

gatsby-browser.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* See: https://www.gatsbyjs.org/docs/browser-apis/
55
*/
66

7+
import React from "react"
8+
import browserLang from "browser-lang"
9+
import { withPrefix, GatsbyBrowser } from "gatsby"
10+
711
import Prism from "prism-react-renderer/prism"
812
;(typeof global !== "undefined" ? global : window).Prism = Prism
913

@@ -12,6 +16,53 @@ import "@formatjs/intl-locale/polyfill"
1216
import "@formatjs/intl-numberformat/polyfill"
1317
import "@formatjs/intl-numberformat/locale-data/en"
1418

19+
import Layout from "./src/components/Layout"
20+
import {
21+
supportedLanguages,
22+
defaultLanguage,
23+
isLang,
24+
} from "./src/utils/languages"
25+
import { IS_DEV } from "./src/utils/env"
26+
import { Context } from "./src/types"
27+
1528
// Default languages included:
1629
// https://github.com/FormidableLabs/prism-react-renderer/blob/master/src/vendor/prism/includeLangs.js
1730
require("prismjs/components/prism-solidity")
31+
32+
// Prevents <Layout/> from unmounting on page transitions
33+
// https://www.gatsbyjs.com/docs/layout-components/#how-to-prevent-layout-components-from-unmounting
34+
// @ts-ignore: returning `null` is not accepted by the `GatsbyBrowser` type def.
35+
export const wrapPageElement: GatsbyBrowser<
36+
any,
37+
Context
38+
>["wrapPageElement"] = ({ element, props }) => {
39+
const { location, pageContext } = props
40+
const { pathname, search } = location
41+
const { originalPath } = pageContext
42+
43+
const [, pathLocale] = pathname.split("/")
44+
45+
// client side redirect on paths that don't have a locale in them. Most useful
46+
// on dev env where we don't have server redirects
47+
if (IS_DEV && !isLang(pathLocale)) {
48+
let detected =
49+
window.localStorage.getItem("eth-org-language") ||
50+
browserLang({
51+
languages: supportedLanguages,
52+
fallback: defaultLanguage,
53+
})
54+
55+
if (!isLang(detected)) {
56+
detected = defaultLanguage
57+
}
58+
59+
const queryParams = search || ""
60+
const newUrl = withPrefix(`/${detected}${originalPath}${queryParams}`)
61+
window.localStorage.setItem("eth-org-language", detected)
62+
window.location.replace(newUrl)
63+
64+
return null
65+
}
66+
67+
return <Layout {...props}>{element}</Layout>
68+
}

gatsby-config.ts

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ const config: GatsbyConfig = {
3535
editContentUrl: `https://github.com/ethereum/ethereum-org-website/tree/dev/`,
3636
},
3737
plugins: [
38+
// i18n support
39+
{
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`,
52+
options: {
53+
defaultLocale: `./src/intl/en.json`,
54+
},
55+
},
3856
// Web app manifest
3957
{
4058
resolve: `gatsby-plugin-manifest`,
@@ -247,56 +265,6 @@ const config: GatsbyConfig = {
247265
generateMatchPathRewrites: false,
248266
},
249267
},
250-
// i18n support
251-
{
252-
resolve: `gatsby-source-filesystem`,
253-
options: {
254-
path: path.resolve(`./i18n/locales`),
255-
name: `locale`,
256-
},
257-
},
258-
// Wraps the entire page with a custom layout component
259-
// Note: keep this before the i18n plugin declaration in order to have the
260-
// i18n provider wrapping the layout component
261-
{
262-
resolve: `gatsby-plugin-layout`,
263-
options: {
264-
component: path.resolve(`./src/components/Layout`),
265-
},
266-
},
267-
{
268-
resolve: `gatsby-plugin-react-i18next`,
269-
options: {
270-
localeJsonSourceName: `locale`, // name given to `gatsby-source-filesystem` plugin.
271-
languages: supportedLanguages,
272-
defaultLanguage: defaultLanguage,
273-
generateDefaultLanguagePage: true,
274-
redirect: false,
275-
siteUrl,
276-
trailingSlash: "always",
277-
// i18next options
278-
i18nextOptions: {
279-
fallbackLng: defaultLanguage,
280-
interpolation: {
281-
escapeValue: false,
282-
},
283-
react: {
284-
transSupportBasicHtmlNodes: true,
285-
transKeepBasicHtmlNodesFor: [
286-
"br",
287-
"strong",
288-
"i",
289-
"bold",
290-
"b",
291-
"em",
292-
"sup",
293-
],
294-
},
295-
keySeparator: false,
296-
nsSeparator: false,
297-
},
298-
},
299-
},
300268
],
301269
// https://www.gatsbyjs.com/docs/reference/release-notes/v2.28/#feature-flags-in-gatsby-configjs
302270
flags: {

0 commit comments

Comments
 (0)