Skip to content

Commit

Permalink
ci: add workflows of integrate with crowdin (#2146)
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee authored Jul 3, 2024
1 parent 8eb1877 commit aaf85ef
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/crowdin-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Crowdin PR

on:
workflow_dispatch:
inputs:
export_only_approved:
description: "Include approved translations only in exported files. If not combined with --skip-untranslated-strings option, strings without approval are fulfilled with the source language"
default: false
type: boolean
required: false
schedule:
- cron: "0 0 * * *" # Every day 0 o'clock

permissions:
contents: write
pull-requests: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
pull:
name: Synchronize with Crowdin
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1 # Should be 1 to avoid parallel builds
matrix:
lc: [ko, pt-BR, ru, th, zh-CN, zh-TW] # Target languages https://developer.crowdin.com/language-codes/
steps:
- uses: actions/checkout@v4

- name: Get BOT token
id: get_bot_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: "site"

- name: Download Translations && Create PR
uses: crowdin/github-action@v2
with:
upload_sources: false
push_sources: false

upload_translations: false
push_translations: true
download_translations: true
create_pull_request: true

export_only_approved: ${{ inputs.export_only_approved || false }}
commit_message: "l10n(${{ matrix.lc }}): New translations from Crowdin"
localization_branch_name: l10n_${{ github.ref_name }}_${{ matrix.lc }}
pull_request_base_branch_name: ${{ github.ref_name }}
pull_request_title: "l10n(${{ matrix.lc }}): New translations from Crowdin"
pull_request_labels: "crowdin"
download_language: ${{ matrix.lc }}
skip_ref_checkout: false
github_user_name: "hexo-crowdin[bot]"
github_user_email: "159447924+hexo-crowdin[bot]@users.noreply.github.com"

crowdin_branch_name: ${{ github.ref_name }}
config: "crowdin.yml"
env:
GITHUB_TOKEN: ${{ steps.get_bot_token.outputs.token }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
51 changes: 51 additions & 0 deletions .github/workflows/crowdin-upload-tran.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Crowdin Upload Translations

on:
workflow_dispatch:
inputs:
auto_approve_imported:
description: "Automatically approves uploaded translations"
default: false
type: boolean
required: false
import_eq_suggestions:
description: "Defines whether to add translation if it is equal to source string in Crowdin project"
default: false
type: boolean
required: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
upload-translation:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1 # Should be 1 to avoid parallel builds
matrix:
lc: [ko, pt-BR, ru, th, zh-CN, zh-TW] # Target languages https://developer.crowdin.com/language-codes/
steps:
- uses: actions/checkout@v4

- uses: crowdin/github-action@v2
with:
upload_sources: false
push_sources: false

upload_translations: true
push_translations: false
download_translations: false
create_pull_request: false

upload_language: ${{ matrix.lc }}
auto_approve_imported: ${{ inputs.auto_approve_imported || false }}
import_eq_suggestions: ${{ inputs.import_eq_suggestions || false }}

crowdin_branch_name: ${{ github.ref_name }}
config: "crowdin.yml"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
45 changes: 45 additions & 0 deletions .github/workflows/crowdin-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Crowdin Upload Sources

on:
workflow_dispatch:

push:
branches:
- "master"
paths:
- "source/about/*.md"
- "source/api/*.md"
- "source/docs/*.md"
- "source/*.md"
- ".github/workflows/crowdin-upload.yml"
- "./crowdin.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
upload-source:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 1 # Should be 1 to avoid parallel builds
steps:
- uses: actions/checkout@v4

- uses: crowdin/github-action@v2
with:
upload_sources: true
push_sources: false

upload_translations: false
push_translations: false
download_translations: false
create_pull_request: false

crowdin_branch_name: ${{ github.ref_name }}
config: "crowdin.yml"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Tester](https://github.com/hexojs/site/actions/workflows/tester.yml/badge.svg)](https://github.com/hexojs/site/actions/workflows/tester.yml)
[![Netlify Status](https://api.netlify.com/api/v1/badges/beeb7e86-4485-4381-8529-6b2a92df5dd7/deploy-status)](https://app.netlify.com/sites/hexo-site/deploys)
[![Crowdin](https://badges.crowdin.net/hexo/localized.svg)](https://crowdin.com/project/hexo)

The website for Hexo.

Expand Down
36 changes: 36 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
project_id_env: CROWDIN_PROJECT_ID
api_token_env: CROWDIN_PERSONAL_TOKEN
base_path: "."
base_url: "https://api.crowdin.com"
preserve_hierarchy: true
commit_message: "l10n(%two_letters_code%): New translations `%original_file_name%` from Crowdin"
append_commit_message: false
pull_request_title: "l10n: New Crowdin updates"
pull_request_labels":
- "crowdin"
- "l10n"

languages_mapping: &languages_mapping
two_letters_code:
zh-CN: zh-cn
zh-TW: zh-tw
pt-BR: pt-br

files:
- source: "source/api/*.md"
translation: "/source/%two_letters_code%/api/%original_file_name%"
update_option: update_as_unapproved
type: fm_md
languages_mapping: *languages_mapping

- source: "source/docs/*.md"
translation: "/source/%two_letters_code%/docs/%original_file_name%"
update_option: update_as_unapproved
type: fm_md
languages_mapping: *languages_mapping

- source: "source/*.md"
translation: "/source/%two_letters_code%/%original_file_name%"
update_option: update_as_unapproved
type: fm_md
languages_mapping: *languages_mapping

0 comments on commit aaf85ef

Please sign in to comment.