Skip to content

Commit

Permalink
Automatically update translations from crowdin daily
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Mar 16, 2024
1 parent 1822d58 commit 0e8ec02
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 24 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Run Daily Tasks

on:
schedule:
- cron: "0 1 * * *"
workflow_dispatch:

permissions:
contents: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Print dotnet version
run: dotnet --info

- name: Checkout Docs
uses: actions/checkout@v4
with:
path: velopack.docs

- name: Checkout Velopack
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: velopack/velopack
path: velopack

- name: Checkout Fusion
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: velopack/velopack.fusion
path: velopack.fusion

- name: Install dependencies
working-directory: velopack.docs
run: npm ci

- name: Run Tasks
working-directory: velopack.docs
run: npm run daily-tasks

- uses: actions4git/add-commit-push@v1
with:
path: velopack.docs
commit-author: github-actions
commit-message: "Update translations / reference libraries"

2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
uses: actions/checkout@v3
- name: Install dependencies
run: npm ci
- name: Upload to Crowdin
run: npm run crowdin-upload
- name: Build
run: npm run build
- name: Setup Pages
Expand Down
47 changes: 47 additions & 0 deletions daily-tasks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import { setTimeout } from 'timers/promises';
import { fileURLToPath } from 'url';

// config
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const locales = ['zh-CN'];
const i18nDir = path.join(__dirname, 'i18n');

// update reference libraries
console.log("Updating reference libraries");
execSync("npm run generate", { stdio: 'inherit' });

// publish latest documentation to crowdin
console.log("Writing docusaurus translations");
execSync("npm run write-translations", { stdio: 'inherit' });

// give crowdin time to process uploaded files
await setTimeout(10 * 1000);

// download and fix up translations from crowdin
console.log("Preparing to download translations from Crowdin");
if (fs.existsSync(i18nDir)) {
locales.forEach(locale => {
const localeDir = path.join(i18nDir, locale);
if (fs.existsSync(localeDir)) {
console.log(`Cleaning "${locale}"`);
fs.rmSync(localeDir, { recursive: true });
}
});
}

console.log('Downloading translations from Crowdin');
execSync("npm run crowdin-download", { stdio: 'inherit' });

console.log('Renaming "zh" directory to "zh-CN"');
fs.renameSync(path.join(i18nDir, 'zh'), path.join(i18nDir, 'zh-CN'));

const referenceDir = path.join(__dirname, 'docs', 'reference');
locales.forEach(locale => {
const localeDir = path.join(i18nDir, locale, 'docusaurus-plugin-content-docs', 'current', 'reference');
console.log(`Copying reference lib to "${locale}"`);
fs.cpSync(referenceDir, localeDir, { recursive: true });
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"generate": "ts-node ./generate.ts",
"crowdin-download": "crowdin download",
"crowdin-upload": "crowdin upload",
"locale": "node setup-locale.js"
"daily-tasks": "node daily-tasks.mjs"
},
"dependencies": {
"@docusaurus/core": "3.1.1",
Expand Down
23 changes: 0 additions & 23 deletions setup-locale.js

This file was deleted.

0 comments on commit 0e8ec02

Please sign in to comment.