Skip to content

Commit

Permalink
docs: pre-translate project
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Jun 11, 2023
1 parent ad33948 commit 81c9fdb
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Update file](#update-file)
- [Create TM](#create-tm)
- [Create Glossary](#create-glossary)
- [Pre-Translate project](#pre-translate-project)

---

Expand Down Expand Up @@ -77,6 +78,7 @@ async function createTm(languageId: string, name: string, fileName: string, file
storageId: storage.data.id,
scheme
});

let status = importTm.data.status;
while (status !== 'finished') {
const progress = await translationMemoryApi.checkImportStatus(tm.data.id, importTm.data.identifier);
Expand Down Expand Up @@ -113,6 +115,7 @@ async function createGlossary(languageId: string, name: string, fileName: string
storageId: storage.data.id,
scheme
});

let status = importGlossary.data.status;
while (status !== 'finished') {
const progress = await glossariesApi.checkGlossaryImportStatus(glossary.data.id, importGlossary.data.identifier);
Expand All @@ -130,3 +133,38 @@ const schema = {
createGlossary('uk', 'test', file, fileContent, schema);

```

## Pre-Translate project

```typescript
import crowdin from '@crowdin/crowdin-api-client';

const { translationsApi } = new crowdin({
token: 'token',
organization: 'org'
});

async function preTranslateProject(projectId: number, languageIds: string[], fileIds: number[]): Promise<string> {
const result = await translationsApi.applyPreTranslation(projectId, {
languageIds,
fileIds,
});

let status = result.data.status;
while (status !== 'finished') {
const progress = await translationsApi.preTranslationStatus(projectId, result.data.identifier);
status = progress.data.status;
}

//as an example we export translations for 1 file and 1 language
const translations = await translationsApi.exportProjectTranslation(projectId, {
targetLanguageId: languageIds[0],
fileIds: [fileIds[0]],
});

return translations.data.url;
}

preTranslateProject(123, ['uk'], [456]);

```

0 comments on commit 81c9fdb

Please sign in to comment.