feat(website): add translation progress

Closes #1173
Closes #1170
Closes #1102
This commit is contained in:
Misite Bao
2023-05-18 20:24:25 +08:00
committed by Andrey Nering
parent 3eab444c03
commit 785fc4ac3c
4 changed files with 315 additions and 189 deletions

50
docs/src/api/crowdin.js Normal file
View File

@@ -0,0 +1,50 @@
const crowdin = require('@crowdin/crowdin-api-client');
const personalToken = process.env.CROWDIN_PERSONAL_TOKEN;
const projectId = '574591';
/**
* Initialization of crowdin client
* @return {object} crowdin client
*/
const initClient = () => {
if (!personalToken) {
console.warn(
'No crowding personal token, some features might not work as expected'
);
return null;
}
return new crowdin.default({
token: personalToken
});
};
/**
* Get translation progress
* @return {object} translation progress
*/
async function getTranslationProgress() {
let translationProgress = {};
const { translationStatusApi } = initClient() || {};
if (!translationStatusApi) {
return translationProgress;
}
await translationStatusApi
.getProjectProgress(projectId)
.then((res) => {
res.data.forEach((item) => {
translationProgress[item.data.languageId] = item.data.approvalProgress;
});
})
.catch((err) => {
console.error(err);
});
return translationProgress;
}
module.exports = {
getTranslationProgress
};