Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Apply Pre-Translation API: add labels support #306

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 39 additions & 0 deletions tests/translations/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
const directoryId = 61;
const progress = 50;
const languageId = 'uk';
const sampleLabelIds = [101, 102];
const sampleExcludeLabelIds = [103, 104];


Check failure on line 24 in tests/translations/api.test.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Delete `⏎`
const limit = 25;

beforeAll(() => {
Expand Down Expand Up @@ -175,6 +178,29 @@
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,
}

Check failure on line 202 in tests/translations/api.test.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Insert `,`
}

Check failure on line 203 in tests/translations/api.test.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Insert `,`
});
});

Expand All @@ -190,6 +216,19 @@
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);

Check failure on line 227 in tests/translations/api.test.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Delete `·`
expect(preTranslation.data.attributes.excludeLabelIds).toEqual(sampleExcludeLabelIds);

Check failure on line 228 in tests/translations/api.test.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Delete `·`
});

Check failure on line 229 in tests/translations/api.test.ts

View workflow job for this annotation

GitHub Actions / code-coverage

Delete `⏎····`


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