5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 08:41:41 +08:00

refactor crowdin init to not throw without key (#2231)

This commit is contained in:
Oleg Gulevskyy 2022-12-29 00:51:49 +01:00 committed by GitHub
parent 52f872b65c
commit d11b459486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,33 @@
const crowdin = require("@crowdin/crowdin-api-client");
const personalToken = process.env.CROWDIN_PERSONAL_TOKEN;
const projectId = 531392;
// initialization of crowdin client
const { translationStatusApi } = new crowdin.default({
token: process.env.CROWDIN_PERSONAL_TOKEN,
});
const initClient = async () => {
if (!personalToken) {
console.warn(
"No crowding personal token, some features might not work as expected"
);
return;
}
return new crowdin.default({
token: personalToken,
});
};
const client = initClient() || {};
async function getTranslationProgress() {
let translationProgress = {};
const { translationStatusApi } = client;
await translationStatusApi.getProjectProgress(531392).then((res) => {
// 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;
}