Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from JouwWeb/trigger-machine-translation
Browse files Browse the repository at this point in the history
Trigger machine translation
  • Loading branch information
villermen authored Jul 5, 2020
2 parents a4fb80c + f446fb7 commit 7707568
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
20 changes: 20 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 26 additions & 7 deletions lib/commands/upload_cmds/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,36 @@ 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'));
}

if (
argv.preTranslationEngine &&
argv.preTranslationLanguages &&
argv.preTranslationLanguages.length > 0
) {
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 */
},
};
15 changes: 6 additions & 9 deletions lib/utils/getCrowdinBranch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

0 comments on commit 7707568

Please sign in to comment.