Files
task/website/src/api/crowdin.js
2024-03-21 01:04:07 +00:00

47 lines
1.0 KiB
JavaScript

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 crowdin personal token, some features might not work as expected'
);
return null;
}
return new crowdin.default({
token: personalToken
});
};
/**
* Get translation progress
* @return {object} translation progress
*/
export 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;
}