Skip to content

Commit 8d7b4d1

Browse files
feat(translations): add new pre-translate parameters (#681)
1 parent 1f277bc commit 8d7b4d1

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

src/translations/index.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,36 +317,56 @@ export namespace TranslationsModel {
317317
languageIds: string[];
318318
fileIds: number[];
319319
method?: Method;
320+
priority?: Priority;
320321
engineId?: number;
321322
aiPromptId?: number;
322323
autoApproveOption?: AutoApproveOption;
323324
duplicateTranslations?: boolean;
324325
skipApprovedTranslations?: boolean;
326+
/**
327+
* @deprecated Use {@link scope} instead
328+
*/
325329
translateUntranslatedOnly?: boolean;
330+
scope?: Scope;
331+
translationModifiedBefore?: string;
332+
replaceTranslationsOption?: ReplaceTranslationsOption;
333+
resetApprovalStatus?: boolean;
326334
translateWithPerfectMatchOnly?: boolean;
327335
fallbackLanguages?: {
328336
languageId?: string[];
329337
};
330338
labelIds?: number[];
331339
excludeLabelIds?: number[];
340+
sourceLanguageId?: string;
341+
customInstruction?: string;
332342
}
333343

334344
export interface PreTranslateStringsRequest {
335345
languageIds: string[];
336346
branchIds?: number[];
337347
method?: Method;
348+
priority?: Priority;
338349
engineId?: number;
339350
aiPromptId?: number;
340351
autoApproveOption?: AutoApproveOption;
341352
duplicateTranslations?: boolean;
342353
skipApprovedTranslations?: boolean;
354+
/**
355+
* @deprecated Use {@link scope} instead
356+
*/
343357
translateUntranslatedOnly?: boolean;
358+
scope?: Scope;
359+
translationModifiedBefore?: string;
360+
replaceTranslationsOption?: ReplaceTranslationsOption;
361+
resetApprovalStatus?: boolean;
344362
translateWithPerfectMatchOnly?: boolean;
345363
fallbackLanguages?: {
346364
languageId: string[];
347365
};
348366
labelIds?: number[];
349367
excludeLabelIds?: number[];
368+
sourceLanguageId?: string;
369+
customInstruction?: string;
350370
}
351371

352372
export interface BuildProjectDirectoryTranslationRequest {
@@ -407,7 +427,16 @@ export namespace TranslationsModel {
407427

408428
export type Method = 'tm' | 'mt' | 'ai';
409429

410-
export type AutoApproveOption = 'all' | 'exceptAutoSubstituted' | 'perfectMatchOnly' | 'none';
430+
export type AutoApproveOption =
431+
| 'all'
432+
| 'exceptAutoSubstituted'
433+
| 'perfectMatchOnly'
434+
| 'perfectMatchApprovedOnly'
435+
| 'none';
436+
437+
export type Scope = 'untranslated' | 'translated' | 'all';
438+
439+
export type ReplaceTranslationsOption = 'none' | 'autoTranslated' | 'all';
411440

412441
export type Priority = 'low' | 'normal' | 'high';
413442

tests/translations/api.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,32 @@ describe('Translations API', () => {
355355
},
356356
},
357357
)
358+
.reply(200, {
359+
data: {
360+
identifier: preTranslationId,
361+
attributes: {},
362+
},
363+
})
364+
.post(
365+
`/projects/${projectId}/pre-translations`,
366+
{
367+
languageIds: [],
368+
fileIds: [],
369+
method: 'ai',
370+
priority: 'high',
371+
scope: 'untranslated',
372+
translationModifiedBefore: '2024-01-01T00:00:00+00:00',
373+
replaceTranslationsOption: 'autoTranslated',
374+
resetApprovalStatus: true,
375+
sourceLanguageId: 'en',
376+
customInstruction: 'Translate formally',
377+
},
378+
{
379+
reqheaders: {
380+
Authorization: `Bearer ${api.token}`,
381+
},
382+
},
383+
)
358384
.reply(200, {
359385
data: {
360386
identifier: preTranslationId,
@@ -392,6 +418,22 @@ describe('Translations API', () => {
392418
expect(preTranslation.data.identifier).toBe(preTranslationId);
393419
});
394420

421+
it('Apply Pre-Translation with new options', async () => {
422+
const preTranslation = await api.applyPreTranslation(projectId, {
423+
fileIds: [],
424+
languageIds: [],
425+
method: 'ai',
426+
priority: 'high',
427+
scope: 'untranslated',
428+
translationModifiedBefore: '2024-01-01T00:00:00+00:00',
429+
replaceTranslationsOption: 'autoTranslated',
430+
resetApprovalStatus: true,
431+
sourceLanguageId: 'en',
432+
customInstruction: 'Translate formally',
433+
});
434+
expect(preTranslation.data.identifier).toBe(preTranslationId);
435+
});
436+
395437
it('Pre-translation status', async () => {
396438
const preTranslation = await api.preTranslationStatus(projectId, preTranslationId);
397439
expect(preTranslation.data.identifier).toBe(preTranslationId);

0 commit comments

Comments
 (0)