Skip to content

Commit 5327dcb

Browse files
committed
Working on translations, its broken but in progress
1 parent bd0e1f5 commit 5327dcb

File tree

8 files changed

+129
-42
lines changed

8 files changed

+129
-42
lines changed

data/siteText/text.json

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
{
2-
"home": [
3-
"Jose Miguel Yolan Najarro is a rapper and poet. This is a space for you to explore his writings, music and works. We also invite you to respond to Jose, and engage in dialogue with him and the community around this website.",
4-
"Jose is currently detained at Adelanto detention center in California. All work shown here was received via mail or phone before August 12th. The next set of community responses will be sent to Jose on August 18th."
5-
],
6-
"addResponse": [
7-
"We encourage visitors who visit this website, to respond to Jose's work. All responses are publically visible to website visitors. They will also be sent, via mail or read via phone to Jose. We expect to send the next set of responses to Jose on August 18th, 2020.",
8-
"If you wish to engage with Jose using audio, you can email us an audio file at bhaviksingh@gmail.com. You can also email us to request audio of Jose's rapping, if you want to add beats on it"
9-
],
10-
"learnMore": [
11-
"We encourage visitors who visit this website, to respond to Jose's work. All responses are publically visible to website visitors. They will also be sent, via mail or read via phone to Jose. We expect to send the next set of responses to Jose on August 18th, 2020."
12-
],
13-
"buttons": {
14-
"addResponse": "add a response",
15-
"closeAddAResponse": "close",
16-
"seeResponse": "responses",
17-
"seeHome": "home",
18-
"seeAbout": "about"
2+
"en": {
3+
"home": [
4+
"Jose Miguel Yolan Najarro is a rapper and poet. This is a space for you to explore his writings, music and works. We also invite you to respond to Jose, and engage in dialogue with him and the community around this website.",
5+
"Jose is currently detained at Adelanto detention center in California. All work shown here was received via mail or phone before August 12th. The next set of community responses will be sent to Jose on August 18th."
6+
],
7+
"addResponse": [
8+
"We encourage visitors who visit this website, to respond to Jose's work. All responses are publically visible to website visitors. They will also be sent, via mail or read via phone to Jose. We expect to send the next set of responses to Jose on August 18th, 2020.",
9+
"If you wish to engage with Jose using audio, you can email us an audio file at bhaviksingh@gmail.com. You can also email us to request audio of Jose's rapping, if you want to add beats on it"
10+
],
11+
"learnMore": [
12+
"We encourage visitors who visit this website, to respond to Jose's work. All responses are publically visible to website visitors. They will also be sent, via mail or read via phone to Jose. We expect to send the next set of responses to Jose on August 18th, 2020."
13+
],
14+
"buttons": {
15+
"addResponse": "add a response",
16+
"closeAddAResponse": "close",
17+
"seeResponse": "responses",
18+
"seeHome": "home",
19+
"seeAbout": "about"
20+
}
21+
},
22+
"es": {
23+
"home": ["SHUMPSHUMPSHUMPSHUMP", "CRUMPCRUMPCRUMPCRUMP"],
24+
"addResponse": [
25+
"We encourage visitors who visit this website, to respond to Jose's work. All responses are publically visible to website visitors. They will also be sent, via mail or read via phone to Jose. We expect to send the next set of responses to Jose on August 18th, 2020.",
26+
"If you wish to engage with Jose using audio, you can email us an audio file at bhaviksingh@gmail.com. You can also email us to request audio of Jose's rapping, if you want to add beats on it"
27+
],
28+
"learnMore": [
29+
"We encourage visitors who visit this website, to respond to Jose's work. All responses are publically visible to website visitors. They will also be sent, via mail or read via phone to Jose. We expect to send the next set of responses to Jose on August 18th, 2020."
30+
],
31+
"buttons": {
32+
"addResponse": "add a response",
33+
"closeAddAResponse": "close",
34+
"seeResponse": "responses",
35+
"seeHome": "home",
36+
"seeAbout": "about"
37+
}
1938
}
2039
}

gatsby-node.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
const locales = {
2+
en: {
3+
path: "en",
4+
locale: "English",
5+
default: true,
6+
},
7+
es: {
8+
path: "es",
9+
locale: "Spanish",
10+
},
11+
}
12+
113
exports.createPages = async ({ actions, graphql, reporter }) => {
214
// Query all the pieces / projects and get their slug
315
// We need this slug -> piece mapping because we'll create a piece for each slug, and we reference the piece by its slug in pieceData.
@@ -34,3 +46,29 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
3446
})
3547
})
3648
}
49+
50+
//This function goes in and for EVERY PAGE deletes it and RECREATES another page for it in spanish
51+
//An optimization here is that we can not delete it, and just create *an extra one* in spanish
52+
exports.onCreatePage = ({ page, actions }) => {
53+
const { createPage, deletePage } = actions
54+
55+
return new Promise(resolve => {
56+
deletePage(page)
57+
58+
Object.keys(locales).map(lang => {
59+
const localizedPath = locales[lang].default
60+
? page.path
61+
: locales[lang].path + page.path
62+
63+
return createPage({
64+
...page,
65+
path: localizedPath,
66+
context: {
67+
locale: lang,
68+
},
69+
})
70+
})
71+
72+
resolve()
73+
})
74+
}

src/components/navBanner.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ export default function NavBanner({ pageURL }) {
1010
allSiteTextJson {
1111
edges {
1212
node {
13-
buttons {
14-
addResponse
15-
seeResponse
16-
seeHome
17-
seeAbout
18-
closeAddAResponse
13+
en {
14+
buttons {
15+
addResponse
16+
seeResponse
17+
seeHome
18+
seeAbout
19+
closeAddAResponse
20+
}
1921
}
2022
}
2123
}
2224
}
2325
}
2426
`)
2527

26-
const buttonNames = data.allSiteTextJson.edges[0].node.buttons
28+
const buttonNames = data.allSiteTextJson.edges[0].node.en.buttons
2729

2830
const [addResponseOpen, setAddResponseOpen] = useState(false)
2931

src/components/pieces/addResponse.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ export default function AddResponse({ isOpen }) {
99
allSiteTextJson {
1010
edges {
1111
node {
12-
addResponse
12+
en {
13+
addResponse
14+
}
1315
}
1416
}
1517
}
1618
}
1719
`)
1820

19-
let addResponseText = data.allSiteTextJson.edges[0].node.addResponse
21+
let addResponseText = data.allSiteTextJson.edges[0].node.en.addResponse
2022

2123
let [inputAuthor, setInputAuthor] = useState("")
2224
let [inputResponse, setInputResponse] = useState("")

src/components/responses/responsePreview.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default function ResponsePreview({ author, response, randomLeftPos }) {
1010
useEffect(() => {
1111
if (bottomPos < 110 && animPlaying) {
1212
const interval_ID = setInterval(() => {
13-
console.log(bottomPos)
1413
setBottomPos(bottomPos => bottomPos + 1)
1514
}, animLength)
1615
return () => {

src/layouts/coreLayout.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import React from "react"
22
import NavBanner from "../components/navBanner"
33

4-
export default function CoreLayout({ children, location }) {
4+
const {
5+
Provider: LocaleProvider,
6+
Consumer: LocaleConsumer,
7+
} = React.createContext()
8+
9+
export default function CoreLayout({ children, location, locale }) {
510
return (
6-
<div className="all-container">
7-
<NavBanner pageURL={location}></NavBanner>
8-
{children}
9-
</div>
11+
<LocaleProvider value={locale}>
12+
<div className="all-container">
13+
<NavBanner pageURL={location}></NavBanner>
14+
{children}
15+
</div>
16+
</LocaleProvider>
1017
)
1118
}
19+
20+
export { LocaleConsumer }

src/pages/about.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { graphql } from "gatsby"
33

44
export default function About({ data }) {
55
//const homeContent = data.home
6-
const aboutData = data.allSiteTextJson.edges[0].node.learnMore
6+
const aboutData = data.allSiteTextJson.edges[0].node.en.learnMore
77
return (
88
<div id="about-container" className="core-container">
99
<div className="content-container flex header-container">
@@ -23,7 +23,9 @@ export const query = graphql`
2323
allSiteTextJson {
2424
edges {
2525
node {
26-
learnMore
26+
en {
27+
learnMore
28+
}
2729
}
2830
}
2931
}

src/pages/index.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
import React from "react"
22
import AllPiecePreview from "../components/pieces/allPiecePreview"
33
import { graphql } from "gatsby"
4+
import LocaleConsumer from "../layouts/coreLayout"
45

56
export default function Home({ data }) {
67
//const homeContent = data.home
7-
const homeData = data.allSiteTextJson.edges[0].node.home
8+
89
return (
910
<div id="home-container" className="core-container">
1011
<div className="content-container flex header-container">
11-
{homeData.map((paragraph, index) => (
12-
<div className="half" key={index}>
13-
{" "}
14-
{paragraph}{" "}
15-
</div>
16-
))}
12+
<LocaleConsumer>
13+
{locale => {
14+
if (!locale) {
15+
alert("No locale available")
16+
locale = "en"
17+
}
18+
console.log("Locale is..." + locale)
19+
const homeData = data.allSiteTextJson.edges[0].node.locale.home
20+
homeData.map((paragraph, index) => (
21+
<div className="half" key={index}>
22+
{" "}
23+
{paragraph}{" "}
24+
</div>
25+
))
26+
}}
27+
</LocaleConsumer>
1728
</div>
1829
<AllPiecePreview></AllPiecePreview>
1930
</div>
@@ -25,7 +36,12 @@ export const query = graphql`
2536
allSiteTextJson {
2637
edges {
2738
node {
28-
home
39+
en {
40+
home
41+
}
42+
es {
43+
home
44+
}
2945
}
3046
}
3147
}

0 commit comments

Comments
 (0)