From 44ff91d631c53a96c34da28a162a9b61892be393 Mon Sep 17 00:00:00 2001 From: Villermen Date: Wed, 25 Mar 2020 11:16:02 +0100 Subject: [PATCH 1/4] Do not attempt to create . directory in upload --- lib/commands/upload_cmds/sources.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/commands/upload_cmds/sources.js b/lib/commands/upload_cmds/sources.js index 06438b9..9083bbc 100644 --- a/lib/commands/upload_cmds/sources.js +++ b/lib/commands/upload_cmds/sources.js @@ -50,13 +50,15 @@ module.exports = { for (const file of argv.files) { process.stdout.write(`- ${file.source}...`); const fileDir = path.dirname(file.source); - createdDirs = await checkDirExists( - API, - createdDirs, - fileDir, - branch, - info, - ); + if (fileDir !== '.') { + createdDirs = await checkDirExists( + API, + createdDirs, + fileDir, + branch, + info, + ); + } await uploadFile(API, file, branch, info); console.log(chalk.green('OK')); From 9dbffd1fe278efa4a788a9f7599d313645d3f68b Mon Sep 17 00:00:00 2001 From: Villermen Date: Wed, 25 Mar 2020 18:35:24 +0100 Subject: [PATCH 2/4] Don't touch git if a branch is specified --- lib/utils/getCrowdinBranch.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/utils/getCrowdinBranch.js b/lib/utils/getCrowdinBranch.js index 12176e4..2e390fe 100644 --- a/lib/utils/getCrowdinBranch.js +++ b/lib/utils/getCrowdinBranch.js @@ -4,15 +4,12 @@ const getBasePath = require('./getBasePath'); module.exports = async function getCrowdinBranch(argv) { const { baseBranches, branch } = argv; - const projectBranch = await gitBranch(path.dirname(getBasePath(argv))); - return new Promise((resolve) => { - const targetBranch = branch || projectBranch; + const targetBranch = branch || await gitBranch(path.dirname(getBasePath(argv))); - if (!targetBranch || baseBranches.includes(targetBranch)) { - resolve(undefined); - } else { - resolve(targetBranch.replace(/\//g, '_')); - } - }); + if (targetBranch && !baseBranches.includes(targetBranch)) { + return targetBranch.replace(/\//g, '_'); + } else { + return undefined; + } }; From 7ebb95782e83f283c69daee65fc56932a118cba3 Mon Sep 17 00:00:00 2001 From: Villermen Date: Wed, 29 Apr 2020 12:14:34 +0200 Subject: [PATCH 3/4] Add pre-translation after upload option --- lib/api.js | 20 ++++++++++++++++++++ lib/commands/upload_cmds/sources.js | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/api.js b/lib/api.js index ae17698..bdfd404 100644 --- a/lib/api.js +++ b/lib/api.js @@ -150,6 +150,26 @@ module.exports = (argv) => ({ return apiCall(argv, 'export', { branch }); }, + async preTranslate(engine, languages, files, branch) { + // Crowdin API does not support a branch argument so we add it to the file + // paths instead. + const fileSources = files.map( + (file) => (branch ? `${branch}/${file.source}` : file.source), + ); + + return dryApiCall( + argv, + 'pre-translate', + {}, + { + method: 'mt', + engine, + 'languages[]': languages, + 'files[]': fileSources, + }, + ); + }, + getDownloadTranslationUrl(branch, language, file) { return getUri(argv.projectIdentifier, 'export-file', { key: argv.apiKey, diff --git a/lib/commands/upload_cmds/sources.js b/lib/commands/upload_cmds/sources.js index 9083bbc..94a8404 100644 --- a/lib/commands/upload_cmds/sources.js +++ b/lib/commands/upload_cmds/sources.js @@ -63,6 +63,19 @@ module.exports = { await uploadFile(API, file, branch, info); console.log(chalk.green('OK')); } + + if (argv.preTranslationEngine && argv.preTranslationLanguages) { + process.stdout.write( + `Pre-translating ${argv.preTranslationLanguages.join(', ')} with ${argv.preTranslationEngine} engine...` + ); + await API.preTranslate( + argv.preTranslationEngine, + argv.preTranslationLanguages, + argv.files, + branch, + ); + console.log(chalk.green('OK')); + } /* eslint-enable */ }, }; From f446fb72730acfe90bd8fbf851b1dee3f48f5a36 Mon Sep 17 00:00:00 2001 From: Villermen Date: Wed, 29 Apr 2020 12:36:48 +0200 Subject: [PATCH 4/4] Do not pre-translate 0 languages --- lib/commands/upload_cmds/sources.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/commands/upload_cmds/sources.js b/lib/commands/upload_cmds/sources.js index 94a8404..ec42cd0 100644 --- a/lib/commands/upload_cmds/sources.js +++ b/lib/commands/upload_cmds/sources.js @@ -64,7 +64,11 @@ module.exports = { console.log(chalk.green('OK')); } - if (argv.preTranslationEngine && argv.preTranslationLanguages) { + if ( + argv.preTranslationEngine && + argv.preTranslationLanguages && + argv.preTranslationLanguages.length > 0 + ) { process.stdout.write( `Pre-translating ${argv.preTranslationLanguages.join(', ')} with ${argv.preTranslationEngine} engine...` );