mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
refactor crowdin init to not throw without key (#2231)
This commit is contained in:
parent
52f872b65c
commit
d11b459486
1 changed files with 23 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue