Skip to content

Commit

Permalink
feat: Apply Pre-Translation API: add labels support (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleGrande authored Oct 6, 2023
1 parent 9560392 commit 70c845b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export namespace TranslationsModel {
translateUntranslatedOnly?: boolean;
translateWithPerfectMatchOnly?: boolean;
markAddedTranslationsAsDone?: boolean;
labelIds?: number[];
excludeLabelIds?: number[];
}

export interface BuildProjectDirectoryTranslationRequest {
Expand Down Expand Up @@ -241,6 +243,8 @@ export namespace TranslationsModel {
duplicateTranslations: boolean;
translateUntranslatedOnly: boolean;
translateWithPerfectMatchOnly: boolean;
labelIds?: number[];
excludeLabelIds?: number[];
}

export type Method = 'tm' | 'mt';
Expand Down
37 changes: 37 additions & 0 deletions tests/translations/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ describe('Translations API', () => {
const directoryId = 61;
const progress = 50;
const languageId = 'uk';
const sampleLabelIds = [101, 102];
const sampleExcludeLabelIds = [103, 104];

const limit = 25;

Expand Down Expand Up @@ -175,6 +177,29 @@ describe('Translations API', () => {
data: {
url: url,
},
})
.post(
`/projects/${projectId}/pre-translations`,
{
languageIds: [],
fileIds: [],
labelIds: sampleLabelIds,
excludeLabelIds: sampleExcludeLabelIds,
},
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
identifier: preTranslationId,
attributes: {
labelIds: sampleLabelIds,
excludeLabelIds: sampleExcludeLabelIds,
},
},
});
});

Expand All @@ -190,6 +215,18 @@ describe('Translations API', () => {
expect(preTranslation.data.identifier).toBe(preTranslationId);
});

it('Apply Pre-Translation with Label Filters', async () => {
const preTranslation = await api.applyPreTranslation(projectId, {
fileIds: [],
languageIds: [],
labelIds: sampleLabelIds,
excludeLabelIds: sampleExcludeLabelIds,
});
expect(preTranslation.data.identifier).toBe(preTranslationId);
expect(preTranslation.data.attributes.labelIds).toEqual(sampleLabelIds);
expect(preTranslation.data.attributes.excludeLabelIds).toEqual(sampleExcludeLabelIds);
});

it('Pre-translation status', async () => {
const preTranslation = await api.preTranslationStatus(projectId, preTranslationId);
expect(preTranslation.data.identifier).toBe(preTranslationId);
Expand Down

0 comments on commit 70c845b

Please sign in to comment.