From bd5b7e5e3fe401d4b7bace56f1b1607602864eed Mon Sep 17 00:00:00 2001 From: Misite Bao Date: Sat, 27 May 2023 10:51:43 +0800 Subject: [PATCH] feat(website): update the `Crowdin` branch (#2688) --- website/Taskfile.yml | 4 ++-- website/crowdin.yml | 2 +- website/package.json | 4 +--- website/src/api/crowdin.js | 31 ++++++++++++++++++++++--------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/website/Taskfile.yml b/website/Taskfile.yml index 08ec69730..5a28355f8 100644 --- a/website/Taskfile.yml +++ b/website/Taskfile.yml @@ -38,10 +38,10 @@ tasks: desc: Upload source files to Crowdin deps: [install] cmds: - - npx crowdin push -b master + - npx crowdin push -b v2 crowdin:pull: desc: Download approved translation files from Crowdin to local deps: [install] cmds: - - npx crowdin pull -b master --export-only-approved + - npx crowdin pull -b v2 --export-only-approved diff --git a/website/crowdin.yml b/website/crowdin.yml index 51b6968e0..d04258c22 100644 --- a/website/crowdin.yml +++ b/website/crowdin.yml @@ -1,4 +1,4 @@ -project_id: 531392 +project_id: "531392" api_token_env: CROWDIN_PERSONAL_TOKEN preserve_hierarchy: true commit_message: "[ci skip]" diff --git a/website/package.json b/website/package.json index fc9dc3ce4..d60613692 100644 --- a/website/package.json +++ b/website/package.json @@ -11,9 +11,7 @@ "clear": "docusaurus clear", "serve": "docusaurus serve", "write-translations": "docusaurus write-translations", - "write-heading-ids": "docusaurus write-heading-ids", - "crowdin": "crowdin", - "crowdin:sync": "docusaurus write-translations && crowdin upload && crowdin download" + "write-heading-ids": "docusaurus write-heading-ids" }, "engines": { "node": ">=18.14.0", diff --git a/website/src/api/crowdin.js b/website/src/api/crowdin.js index 288950e69..61526b05c 100644 --- a/website/src/api/crowdin.js +++ b/website/src/api/crowdin.js @@ -1,6 +1,7 @@ const crowdin = require("@crowdin/crowdin-api-client"); const personalToken = process.env.CROWDIN_PERSONAL_TOKEN; -const projectId = 531392; +const projectId = "531392"; +const branch = "v2"; // initialization of crowdin client const initClient = () => { @@ -16,22 +17,34 @@ const initClient = () => { }); }; -const client = initClient() || {}; - async function getTranslationProgress() { let translationProgress = {}; - const { translationStatusApi } = client; + + const client = initClient() || {}; + const { sourceFilesApi, translationStatusApi } = client; // do nothing if client failed to init if (!translationStatusApi) { return translationProgress; } - await translationStatusApi.getProjectProgress(projectId).then((res) => { - for (const item of res.data) { - translationProgress[item.data.languageId] = item.data.approvalProgress; - } - }); + const branchId = await sourceFilesApi + .listProjectBranches(projectId) + .then((res) => { + for (const item of res.data) { + if (item.data.name == branch) { + return item.data.id; + } + } + }); + + await translationStatusApi + .getBranchProgress(projectId, branchId) + .then((res) => { + for (const item of res.data) { + translationProgress[item.data.languageId] = item.data.approvalProgress; + } + }); return translationProgress; }