Skip to content

Commit 8cf4247

Browse files
IMB11Prospector
andauthored
feat: Reintroduce crowdin synchronization. (#4178)
* feat: crowdin * fix: preflight check * fix: workflow * fix: workflow * fix: fail on preflight failure * fix: crowdin config * fix: ci * fix: crowdin sources * fix: crowdin config * fix: crowdin pull * fix: crowdin * fix: crowdin issues * fix: add-paths * fix: move pr body to markdown template * fix: lint & moderation package * Update Crowdin link in pull request template Signed-off-by: Cal H. <contact@cal.engineer> * Update crowdin links --------- Signed-off-by: Cal H. <contact@cal.engineer> Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
1 parent 006b19e commit 8cf4247

File tree

9 files changed

+222
-19
lines changed

9 files changed

+222
-19
lines changed

.github/templates/crowdin-pr.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This pull request is created according to the `.github/workflows/i18n-pull.yml` file.
2+
3+
- 🌐 [Contribute to translations on Crowdin](https://translate.modrinth.com/)
4+
- 🔄 [Dispatch this workflow again to update this PR](https://github.com/Modrinth/code/actions/workflows/i18n-pull.yml)

.github/workflows/i18n-pull.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Crowdin (pull)
2+
3+
on:
4+
schedule:
5+
- cron: '0 7 * * MON' # every monday at 7 am
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: i18n-management
10+
11+
jobs:
12+
pull_translations:
13+
name: 'Pull translations from Crowdin'
14+
runs-on: ubuntu-22.04
15+
if: github.ref == 'refs/heads/main'
16+
concurrency:
17+
group: i18n-pull:${{ github.ref }}
18+
cancel-in-progress: true
19+
steps:
20+
- name: Preflight check
21+
run: |
22+
PREFLIGHT_CHECK_RESULT=true
23+
24+
function flight_failure () {
25+
if [ "$PREFLIGHT_CHECK_RESULT" = true ]; then
26+
echo "One or more pre-flight checks failed!"
27+
echo ""
28+
PREFLIGHT_CHECK_RESULT=false
29+
fi
30+
echo "- $1"
31+
}
32+
33+
if [ "$CROWDIN_PROJECT_ID_DEFINED" != true ]; then
34+
flight_failure "CROWDIN_PROJECT_ID variable is not defined (required to push)"
35+
fi
36+
37+
if [ "$CROWDIN_PERSONAL_TOKEN_DEFINED" != true ]; then
38+
flight_failure "CROWDIN_PERSONAL_TOKEN secret is not defined (required to push)"
39+
fi
40+
41+
if [ "$CROWDIN_GH_TOKEN_DEFINED" != true ]; then
42+
flight_failure "CROWDIN_GH_TOKEN secret is not defined (required to make pull requests)"
43+
fi
44+
45+
if [ "$PREFLIGHT_CHECK_RESULT" = false ]; then
46+
exit 1
47+
fi
48+
env:
49+
CROWDIN_PROJECT_ID_DEFINED: ${{ vars.CROWDIN_PROJECT_ID != '' }}
50+
CROWDIN_PERSONAL_TOKEN_DEFINED: ${{ secrets.CROWDIN_PERSONAL_TOKEN != '' }}
51+
CROWDIN_GH_TOKEN_DEFINED: ${{ secrets.CROWDIN_GH_TOKEN != '' }}
52+
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
with:
56+
ref: ${{ github.ref }}
57+
token: ${{ secrets.CROWDIN_GH_TOKEN }}
58+
59+
- name: Configure Git author
60+
id: git-author
61+
uses: MarcoIeni/git-config@v0.1
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.CROWDIN_GH_TOKEN }}
64+
65+
# # Because --all flag of Crowdin CLI is currently broken we need to create a fake source file
66+
# # so that the CLI won't omit translations for it. See https://github.com/crowdin/crowdin-cli/issues/724
67+
# - name: Write fake sources
68+
# shell: bash
69+
# run: echo "{}" > locales/en-US/index.json
70+
71+
- name: Query branch name
72+
id: branch-name
73+
shell: bash
74+
run: |
75+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
76+
SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed -e "s/[\\\\/\\:*?\"<>|]/_/g")
77+
echo "Branch name is $BRANCH_NAME (escaped as $SAFE_BRANCH_NAME)"
78+
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
79+
echo "safe_branch_name=$SAFE_BRANCH_NAME" >> "$GITHUB_OUTPUT"
80+
81+
- name: Download translations from Crowdin
82+
uses: crowdin/github-action@v2
83+
with:
84+
upload_sources: false
85+
upload_translations: false
86+
download_translations: true
87+
push_translations: false
88+
create_pull_request: false
89+
crowdin_branch_name: '[${{ github.repository_owner }}.${{ github.event.repository.name }}] ${{ steps.branch-name.outputs.safe_branch_name }}'
90+
env:
91+
CROWDIN_PROJECT_ID: ${{ vars.CROWDIN_PROJECT_ID }}
92+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
93+
94+
- name: Fix broken permissions
95+
shell: bash
96+
run: sudo chown -R $USER:$USER .
97+
98+
- name: Create Pull Request
99+
uses: peter-evans/create-pull-request@v7
100+
with:
101+
title: 'New translations from Crowdin (${{ steps.branch-name.outputs.branch_name }})'
102+
body-path: .github/templates/crowdin-pr.md
103+
commit-message: 'New translations from Crowdin (${{ steps.branch-name.outputs.branch_name }})'
104+
branch: crowdin-pull/${{ steps.branch-name.outputs.branch_name }}
105+
author: '${{ steps.git-author.outputs.name }} <${{ steps.git-author.outputs.email }}>'
106+
committer: '${{ steps.git-author.outputs.name }} <${{ steps.git-author.outputs.email }}>'
107+
labels: sync
108+
token: ${{ secrets.CROWDIN_GH_TOKEN }}

.github/workflows/i18n-push.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Crowdin (push)
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
paths:
7+
- '.github/workflows/i18n.push.yml'
8+
- 'apps/*/src/locales/en-US/**'
9+
- 'apps/*/locales/en-US/**'
10+
- 'packages/*/src/locales/en-US/**'
11+
- 'packages/*/locales/en-US/**'
12+
- 'crowdin.yml'
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: i18n-management
17+
18+
jobs:
19+
push_translations:
20+
name: Push sources to Crowdin
21+
runs-on: ubuntu-22.04
22+
if: github.ref == 'refs/heads/main'
23+
concurrency:
24+
group: i18n-push:${{ github.ref }}
25+
cancel-in-progress: true
26+
steps:
27+
- name: Preflight check
28+
run: |
29+
PREFLIGHT_CHECK_RESULT=true
30+
31+
function flight_failure () {
32+
if [ "$PREFLIGHT_CHECK_RESULT" = true ]; then
33+
echo "One or more pre-flight checks failed!"
34+
echo ""
35+
PREFLIGHT_CHECK_RESULT=false
36+
fi
37+
echo "- $1"
38+
}
39+
40+
if [ "$CROWDIN_PROJECT_ID_DEFINED" != true ]; then
41+
flight_failure "CROWDIN_PROJECT_ID variable is not defined (required to push)"
42+
fi
43+
44+
if [ "$CROWDIN_PERSONAL_TOKEN_DEFINED" != true ]; then
45+
flight_failure "CROWDIN_PERSONAL_TOKEN secret is not defined (required to push)"
46+
fi
47+
48+
if [ "$PREFLIGHT_CHECK_RESULT" = false ]; then
49+
exit 1
50+
fi
51+
env:
52+
CROWDIN_PROJECT_ID_DEFINED: ${{ vars.CROWDIN_PROJECT_ID != '' }}
53+
CROWDIN_PERSONAL_TOKEN_DEFINED: ${{ secrets.CROWDIN_PERSONAL_TOKEN != '' }}
54+
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ github.ref }}
59+
60+
- name: Query branch name
61+
id: branch-name
62+
shell: bash
63+
run: |
64+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
65+
SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed -e "s/[\\\\/\\:*?\"<>|]/_/g")
66+
echo "Branch name is $BRANCH_NAME (escaped as $SAFE_BRANCH_NAME)"
67+
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
68+
echo "safe_branch_name=$SAFE_BRANCH_NAME" >> "$GITHUB_OUTPUT"
69+
70+
- name: Upload translations to Crowdin
71+
uses: crowdin/github-action@v1
72+
with:
73+
upload_sources: true
74+
upload_translations: false
75+
download_translations: false
76+
push_translations: false
77+
create_pull_request: false
78+
crowdin_branch_name: '[${{ github.repository_owner }}.${{ github.event.repository.name }}] ${{ steps.branch-name.outputs.safe_branch_name }}'
79+
env:
80+
CROWDIN_PROJECT_ID: ${{ vars.CROWDIN_PROJECT_ID }}
81+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

apps/docs/public/welcome-channel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
Blog and newsletter: https://modrinth.com/news
7272
API documentation: https://docs.modrinth.com
7373
Modrinth source code: https://github.com/modrinth
74-
Help translate Modrinth: https://crowdin.com/project/modrinth
74+
Help translate Modrinth: https://translate.modrinth.com
7575
Follow Modrinth on Mastodon: https://floss.social/@modrinth
7676
Follow Modrinth on Twitter: https://twitter.com/modrinth
7777

apps/frontend/crowdin.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

apps/frontend/src/layouts/default.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ const footerLinks = [
12811281
),
12821282
},
12831283
{
1284-
href: 'https://crowdin.com/project/modrinth',
1284+
href: 'https://translate.modrinth.com',
12851285
label: formatMessage(
12861286
defineMessage({ id: 'layout.footer.resources.translate', defaultMessage: 'Translate' }),
12871287
),

apps/frontend/src/pages/settings/language.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function getItemLabel(locale: Locale) {
290290
<div class="card-description">
291291
<IntlFormatted :message-id="messages.languagesDescription">
292292
<template #crowdin-link="{ children }">
293-
<a href="https://crowdin.com/project/modrinth">
293+
<a href="https://translate.modrinth.com">
294294
<component :is="() => children" />
295295
</a>
296296
</template>

crowdin.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
preserve_hierarchy: true
2+
commit_message: '[ci skip]'
3+
4+
files:
5+
- source: /apps/app-frontend/src/locales/en-US/*.json
6+
dest: /app/%original_file_name%
7+
translation: /apps/app-frontend/src/locales/%locale%/%original_file_name%
8+
skip_untranslated_strings: true
9+
10+
- source: /apps/frontend/src/locales/en-US/*.json
11+
dest: /web/%original_file_name%
12+
translation: /apps/frontend/src/locales/%locale%/%original_file_name%
13+
skip_untranslated_strings: true
14+
15+
- source: /packages/ui/src/locales/en-US/*.json
16+
dest: /ui/%original_file_name%
17+
translation: /packages/ui/src/locales/%locale%/%original_file_name%
18+
skip_untranslated_strings: true
19+
20+
- source: /packages/moderation/src/locales/en-US/*.json
21+
dest: /moderation/%original_file_name%
22+
translation: /packages/moderation/src/locales/%locale%/%original_file_name%
23+
skip_untranslated_strings: true
24+
25+
project_id_env: CROWDIN_PROJECT_ID
26+
api_token_env: CROWDIN_PERSONAL_TOKEN

packages/ui/crowdin.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)