Skip to content

Commit

Permalink
Api updates (#238)
Browse files Browse the repository at this point in the history
* added translation alignment

* added concordance search in TMs

* added concordance search in Glossaries
  • Loading branch information
yevheniyJ authored Mar 16, 2023
1 parent 7e88692 commit 746373f
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crowdin/crowdin-api-client",
"version": "1.22.0",
"version": "1.22.1",
"description": "JavaScript library for Crowdin API v2.",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
28 changes: 28 additions & 0 deletions src/glossaries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ export class Glossaries extends CrowdinApi {
const url = `${this.url}/glossaries/${glossaryId}/concepts/${conceptId}`;
return this.delete(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.glossaries.concordance.post
*/
concordanceSearch(
projectId: number,
request: GlossariesModel.ConcordanceSearchRequest,
): Promise<ResponseList<GlossariesModel.ConcordanceSearchResponse>> {
const url = `${this.url}/projects/${projectId}/glossaries/concordance`;
return this.post(url, request, this.defaultConfig());
}
}

export namespace GlossariesModel {
Expand All @@ -343,6 +356,8 @@ export namespace GlossariesModel {
terms: number;
languageId: string;
languageIds: string[];
defaultProjectId: number;
defaultProjectIds: number[];
projectIds: number[];
createdAt: string;
}
Expand Down Expand Up @@ -421,6 +436,19 @@ export namespace GlossariesModel {
conceptId?: number;
}

export interface ConcordanceSearchRequest extends PaginationOptions {
sourceLanguageId: string;
targetLanguageId: string;
expression: string;
}

export interface ConcordanceSearchResponse {
glossary: Glossary;
concept: Concept;
sourceTerms: Term[];
targetTerms: Term[];
}

export type Status = 'preferred' | 'admitted' | 'not recommended' | 'obsolete';

export type Type = 'full form' | 'acronym' | 'abbreviation' | 'short form' | 'phrase' | 'variant';
Expand Down
33 changes: 33 additions & 0 deletions src/stringTranslations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ export class StringTranslations extends CrowdinApi {
return this.getList(url, options.limit, options.offset);
}

/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.translations.alignment.post
*/
translationAlignment(
projectId: number,
request: StringTranslationsModel.TranslationAlignmentRequest,
): Promise<ResponseObject<StringTranslationsModel.TranslationAlignmentResponse>> {
const url = `${this.url}/projects/${projectId}/translations/alignment`;
return this.post(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param stringId string identifier
Expand Down Expand Up @@ -456,6 +469,26 @@ export namespace StringTranslationsModel {
createdAt: string;
}

export interface TranslationAlignmentRequest {
sourceLanguageId: string;
targetLanguageId: string;
text: string;
}

export interface TranslationAlignmentResponse {
words: {
text: string;
alignments: {
sourceWord: string;
sourceLemma: string;
targetWord: string;
targetLemma: string;
match: number;
probability: number;
}[];
}[];
}

export interface AddStringTranslationRequest {
stringId: number;
languageId: string;
Expand Down
32 changes: 32 additions & 0 deletions src/translationMemory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ export class TranslationMemory extends CrowdinApi {
return this.get(url, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param request request body
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.tms.concordance.post
*/
concordanceSearch(
projectId: number,
request: TranslationMemoryModel.ConcordanceSearchRequest,
): Promise<ResponseList<TranslationMemoryModel.ConcordanceSearchResponse>> {
const url = `${this.url}/projects/${projectId}/tms/concordance`;
return this.post(url, request, this.defaultConfig());
}

/**
* @param tmId tm identifier
* @param request request body
Expand Down Expand Up @@ -171,6 +184,7 @@ export namespace TranslationMemoryModel {
languageIds: string[];
segmentsCount: number;
defaultProjectId: number;
defaultProjectIds: number[];
projectIds: number[];
createdAt: string;
}
Expand All @@ -181,6 +195,24 @@ export namespace TranslationMemoryModel {
groupId?: number;
}

export interface ConcordanceSearchRequest {
sourceLanguageId: string;
targetLanguageId: string;
autoSubstitution: boolean;
minRelevant: number;
expression: string;
}

export interface ConcordanceSearchResponse {
tm: TranslationMemory;
recordId: number;
source: string;
target: string;
relevant: number;
substituted: string;
updatedAt: string;
}

export interface ExportTranslationMemoryRequest {
sourceLanguageId?: number;
targetLanguageId?: number;
Expand Down
41 changes: 40 additions & 1 deletion tests/glossaries/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Glossaries API', () => {
const termLanguageId = 'fr';
const limit = 25;
const groupId = 111;
const projectId = 123;

const conceptId = 983;
const subject = 'test';
Expand Down Expand Up @@ -305,7 +306,35 @@ describe('Glossaries API', () => {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200);
.reply(200)
.post(
`/projects/${projectId}/glossaries/concordance`,
{
sourceLanguageId: termLanguageId,
targetLanguageId: termLanguageId,
expression: 'Welcome!',
},
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: [
{
data: {
glossary: {
id: glossaryId,
},
},
},
],
pagination: {
offset: 0,
limit: limit,
},
});
});

afterAll(() => {
Expand Down Expand Up @@ -448,4 +477,14 @@ describe('Glossaries API', () => {
it('Delete concept', async () => {
await api.deleteConcept(glossaryId, conceptId);
});

it('Concordance search', async () => {
const res = await api.concordanceSearch(projectId, {
sourceLanguageId: termLanguageId,
targetLanguageId: termLanguageId,
expression: 'Welcome!',
});
expect(res.data.length).toBe(1);
expect(res.data[0].data.glossary.id).toBe(glossaryId);
});
});
24 changes: 24 additions & 0 deletions tests/stringTranslations/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ describe('String Translations API', () => {
limit: limit,
},
})
.post(`/projects/${projectId}/translations/alignment`, {
sourceLanguageId: languageId,
targetLanguageId: languageId,
text: 'test',
})
.reply(200, {
data: {
words: [
{
text: 'test',
},
],
},
})
.get(`/projects/${projectId}/translations`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
Expand Down Expand Up @@ -256,6 +270,16 @@ describe('String Translations API', () => {
expect(translations.pagination.limit).toBe(limit);
});

it('Translation Alignment', async () => {
const res = await api.translationAlignment(projectId, {
sourceLanguageId: languageId,
targetLanguageId: languageId,
text: 'test',
});
expect(res.data.words.length).toBe(1);
expect(res.data.words[0].text).toBe('test');
});

it('List String Translations', async () => {
const translations = await api.listStringTranslations(projectId, stringId, languageId);
expect(translations.data.length).toBe(1);
Expand Down
43 changes: 43 additions & 0 deletions tests/translationMemory/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Translation Memory API', () => {
const tmId = 2;
const groupId = 44;
const storageId = 55;
const projectId = 77;
const exportId = '3';
const importId = '4';
const name = 'test';
Expand Down Expand Up @@ -113,6 +114,36 @@ describe('Translation Memory API', () => {
url: url,
},
})
.post(
`/projects/${projectId}/tms/concordance`,
{
sourceLanguageId: languageId,
targetLanguageId: languageId,
autoSubstitution: true,
minRelevant: 60,
expression: 'Welcome!',
},
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: [
{
data: {
tm: {
id: tmId,
},
},
},
],
pagination: {
offset: 0,
limit: limit,
},
})
.post(
`/tms/${tmId}/exports`,
{},
Expand Down Expand Up @@ -215,6 +246,18 @@ describe('Translation Memory API', () => {
expect(link.data.url).toBe(url);
});

it('Concordance search in TMs', async () => {
const res = await api.concordanceSearch(projectId, {
autoSubstitution: true,
expression: 'Welcome!',
minRelevant: 60,
sourceLanguageId: languageId,
targetLanguageId: languageId,
});
expect(res.data.length).toBe(1);
expect(res.data[0].data.tm.id).toBe(tmId);
});

it('Export TM', async () => {
const status = await api.exportTm(tmId, {});
expect(status.data.identifier).toBe(exportId);
Expand Down

0 comments on commit 746373f

Please sign in to comment.