Skip to content

Commit 64d911f

Browse files
authored
Merge pull request #10616 from ethereum/addTranslatorsToContributors
Add Translators as contributors on non-English docs/tutorials
2 parents d080ea9 + d9c052c commit 64d911f

24 files changed

+54320
-88
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Update Crowdin Contributors
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * SUN" # Runs every Sunday at midnight
6+
workflow_dispatch:
7+
8+
jobs:
9+
create_pr:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
20+
- name: Install dependencies
21+
run: yarn install
22+
23+
- name: Install ts-node
24+
run: yarn global add ts-node
25+
26+
- name: Set up git
27+
run: |
28+
git config --global user.email "actions@github.com"
29+
git config --global user.name "GitHub Action"
30+
31+
- name: Generate timestamp and readable date
32+
id: date
33+
run: |
34+
echo "TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
35+
echo "READABLE_DATE=$(date +'%B %-d')" >> $GITHUB_ENV
36+
37+
- name: Fetch latest dev and create new branch
38+
run: |
39+
git fetch origin dev
40+
git checkout -b "automated-update-${{ env.TIMESTAMP }}" origin/dev
41+
42+
- name: Run script
43+
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/getCrowdinContributors.ts
44+
env:
45+
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }}
46+
47+
- name: Commit and push
48+
run: |
49+
git add -A
50+
git commit -m "Update Crowdin contributors"
51+
git push origin "automated-update-${{ env.TIMESTAMP }}"
52+
53+
- name: Create PR body
54+
run: |
55+
echo "This PR was automatically created to update Crowdin contributors." > pr_body.txt
56+
echo "This workflows runs every Sunday at 00:00 (UTC)." >> pr_body.txt
57+
echo "" >> pr_body.txt
58+
echo "Thank you to everyone contributing to translate ethereum.org ❤️" >> pr_body.txt
59+
60+
- name: Create Pull Request
61+
run: |
62+
gh auth login --with-token <<< ${{ secrets.GITHUB_TOKEN }}
63+
gh pr create --base dev --head "automated-update-${{ env.TIMESTAMP }}" --title "Update translation contributors from Crowdin - ${{ env.READABLE_DATE }}" --body-file pr_body.txt

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@apollo/client": "^3.3.13",
1212
"@chakra-ui/gatsby-plugin": "^3.1.3",
1313
"@chakra-ui/react": "2.6.1",
14+
"@crowdin/crowdin-api-client": "^1.23.2",
1415
"@docsearch/react": "^3.3.3",
1516
"@emotion/react": "^11.9.3",
1617
"@emotion/styled": "^11.9.3",
@@ -131,6 +132,7 @@
131132
"generate-heading-ids": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/generateHeadingIds.ts",
132133
"unused-translations": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/unusedTranslations.ts",
133134
"reorg-intl": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/reorgIntlFiles.ts",
135+
"crowdin-contributors": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/crowdin/getCrowdinContributors.ts",
134136
"start": "gatsby develop",
135137
"start:lambda": "netlify-lambda serve src/lambda",
136138
"start:static": "gatsby build && gatsby serve",

src/components/FileContributors.tsx

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from "react"
22

33
import { useI18next } from "gatsby-plugin-react-i18next"
4-
import { useQuery, gql } from "@apollo/client"
4+
import { gql } from "@apollo/client"
55

66
import {
77
Avatar,
@@ -12,7 +12,6 @@ import {
1212
ListItem,
1313
ModalBody,
1414
ModalHeader,
15-
Show,
1615
Skeleton as ChakraSkeleton,
1716
SkeletonCircle as ChakraSkeletonCircle,
1817
Text,
@@ -31,7 +30,7 @@ import Modal from "./Modal"
3130
import Translation from "./Translation"
3231
import Button from "./Button"
3332

34-
interface Author {
33+
export interface Author {
3534
name: string
3635
email: string
3736
avatarUrl: string
@@ -41,7 +40,7 @@ interface Author {
4140
}
4241
}
4342

44-
interface Commit {
43+
export interface Commit {
4544
author: Author
4645
committedDate: string
4746
}
@@ -121,48 +120,28 @@ const Contributor = ({ contributor }: { contributor: Author }) => {
121120
export interface IProps extends FlexProps {
122121
relativePath: string
123122
editPath?: string
123+
contributors: Array<Author>
124+
lastContributor: any
125+
loading: Boolean
126+
error: any
127+
lastEdit: string
124128
}
125129

126130
const FileContributors: React.FC<IProps> = ({
127131
relativePath,
128132
editPath,
133+
contributors,
134+
lastContributor,
135+
loading,
136+
error,
137+
lastEdit,
129138
...props
130139
}) => {
131140
const [isModalOpen, setModalOpen] = useState(false)
132141
const { language } = useI18next()
133142

134-
const { loading, error, data } = useQuery(COMMIT_HISTORY, {
135-
variables: { relativePath },
136-
})
137-
138143
if (error) return null
139144

140-
const commits: Array<Commit> =
141-
data?.repository?.ref?.target?.history?.edges?.map((commit) => commit.node)
142-
143-
const lastCommit = commits?.[0] || {}
144-
const lastContributor = lastCommit?.author || {}
145-
const uniqueContributors =
146-
commits?.reduce(
147-
(res: Array<Author>, cur: Commit) => {
148-
if (cur.author.user === null) {
149-
return res
150-
}
151-
for (const contributor of res) {
152-
const hasAuthorInfo = !!contributor.user && !!cur.author.user
153-
if (
154-
hasAuthorInfo &&
155-
contributor.user.login === cur.author.user.login
156-
) {
157-
return res
158-
}
159-
}
160-
res.push(cur.author)
161-
return res
162-
},
163-
[lastContributor]
164-
) || []
165-
166145
return (
167146
<>
168147
<Modal isOpen={isModalOpen} setIsOpen={setModalOpen}>
@@ -174,12 +153,16 @@ const FileContributors: React.FC<IProps> = ({
174153

175154
<ModalBody>
176155
<Translation id="contributors-thanks" />
177-
178-
<ContributorList>
179-
{uniqueContributors.map((contributor) => (
180-
<Contributor contributor={contributor} key={contributor.email} />
181-
))}
182-
</ContributorList>
156+
{contributors ? (
157+
<ContributorList>
158+
{contributors.map((contributor) => (
159+
<Contributor
160+
contributor={contributor}
161+
key={contributor.email}
162+
/>
163+
))}
164+
</ContributorList>
165+
) : null}
183166
</ModalBody>
184167
</Modal>
185168

@@ -211,7 +194,7 @@ const FileContributors: React.FC<IProps> = ({
211194
</Link>
212195
)}
213196
{!lastContributor.user && <span>{lastContributor.name}</span>},{" "}
214-
{getLocaleTimestamp(language as Lang, lastCommit.committedDate)}
197+
{getLocaleTimestamp(language as Lang, lastEdit)}
215198
</Text>
216199
</Skeleton>
217200
</Flex>
@@ -235,24 +218,25 @@ const FileContributors: React.FC<IProps> = ({
235218
<Translation id="see-contributors" />
236219
</Button>
237220
</Skeleton>
238-
239221
{editPath && (
240-
<Show below="l">
241-
{/* TODO: switch `l` to `lg` after UI migration and use `hideBelow` prop */}
242-
<ButtonLink to={editPath} hideArrow variant="outline">
243-
<Flex
244-
h="100%"
245-
alignItems="center"
246-
justifyContent="center"
247-
gap={2}
248-
>
249-
<Icon as={FaGithub} fontSize="2xl" />
250-
<span>
251-
<Translation id="edit-page" />
252-
</span>
253-
</Flex>
254-
</ButtonLink>
255-
</Show>
222+
<ButtonLink
223+
to={editPath}
224+
hideArrow
225+
variant="outline"
226+
hideBelow="lg"
227+
>
228+
<Flex
229+
h="100%"
230+
alignItems="center"
231+
justifyContent="center"
232+
gap={2}
233+
>
234+
<Icon as={FaGithub} fontSize="2xl" />
235+
<span>
236+
<Translation id="edit-page" />
237+
</span>
238+
</Flex>
239+
</ButtonLink>
256240
)}
257241
</VStack>
258242
</Flex>

0 commit comments

Comments
 (0)