Skip to content

Commit c2d4367

Browse files
authored
feat: Add new Pre-Translation Report endpoint support (#126)
1 parent a1b22f3 commit c2d4367

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

crowdin/model/translations.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,40 @@ type (
3030
TranslateUntranslatedOnly *bool `json:"translateUntranslatedOnly,omitempty"`
3131
TranslateWithPerfectMatchOnly *bool `json:"translateWithPerfectMatchOnly,omitempty"`
3232
}
33+
34+
PreTranslationReport struct {
35+
Languages []*LanguageReport `json:"languages"`
36+
PreTranslateType string `json:"preTranslateType"`
37+
}
38+
39+
LanguageReport struct {
40+
ID string `json:"id"`
41+
Files []*LanguageReportFile `json:"files"`
42+
Skipped *LanguageReportSkipped `json:"skipped,omitempty"`
43+
SkippedQaCheckCategories *LanguageReportSkippedQaCheckCategories `json:"skippedQaCheckCategories,omitempty"`
44+
}
45+
46+
LanguageReportFile struct {
47+
ID string `json:"id"`
48+
Statistics *LanguageReportStatistics `json:"statistics"`
49+
}
50+
51+
LanguageReportStatistics struct {
52+
Phrases int `json:"phrases"`
53+
Words int `json:"words"`
54+
}
55+
56+
LanguageReportSkipped struct {
57+
TranslationEQSource int `json:"translation_eq_source"`
58+
QACheck int `json:"qa_check"`
59+
HiddenStrings int `json:"hidden_strings"`
60+
AIError int `json:"ai_error"`
61+
}
62+
63+
LanguageReportSkippedQaCheckCategories struct {
64+
Duplicate int `json:"duplicate"`
65+
Spellcheck int `json:"spellcheck"`
66+
}
3367
)
3468

3569
// PreTranslationsResponse defines the structure of a response when
@@ -44,6 +78,12 @@ type PreTranslationsListResponse struct {
4478
Data []*PreTranslationsResponse `json:"data"`
4579
}
4680

81+
// PreTranslationReportResponse defines the structure of a response when
82+
// getting a pre-translation report.
83+
type PreTranslationReportResponse struct {
84+
Data *PreTranslationReport `json:"data"`
85+
}
86+
4787
// PreTranslationRequest defines the structure of a request to apply pre-translation.
4888
type PreTranslationRequest struct {
4989
// Set of languages to which pre-translation should be applied.

crowdin/translations.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ func (s *TranslationsService) ApplyPreTranslation(ctx context.Context, projectID
7777
return res.Data, resp, err
7878
}
7979

80+
// PreTranslationReport returns report data for a specific pre-translation.
81+
//
82+
// https://support.crowdin.com/developer/api/v2/#tag/Translations/operation/api.projects.pre-translations.report.getReport
83+
func (s *TranslationsService) PreTranslationReport(
84+
ctx context.Context, projectID int, preTranslationID string,
85+
) (*model.PreTranslationReport, *Response, error) {
86+
res := new(model.PreTranslationReportResponse)
87+
resp, err := s.client.Get(ctx, fmt.Sprintf("/api/v2/projects/%d/pre-translations/%s/reports", projectID, preTranslationID), nil, res)
88+
89+
return res.Data, resp, err
90+
}
91+
8092
// BuildProjectDirectoryTranslation builds translations for a specific directory in the project.
8193
//
8294
// https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.directories.post

crowdin/translations_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,81 @@ func TestTranslationsService_PreTranslationStatus(t *testing.T) {
6969
assert.Equal(t, http.StatusOK, resp.StatusCode)
7070
}
7171

72+
func TestTranslationsService_PreTranslationReport(t *testing.T) {
73+
client, mux, teardown := setupClient()
74+
defer teardown()
75+
76+
const path = "/api/v2/projects/1/pre-translations/9e7de270-4f83-41cb-b606-2f90631f26e2/reports"
77+
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
78+
testMethod(t, r, http.MethodGet)
79+
testURL(t, r, path)
80+
81+
fmt.Fprint(w, `{
82+
"data": {
83+
"languages": [
84+
{
85+
"id": "es",
86+
"files": [
87+
{
88+
"id": "10191",
89+
"statistics": {
90+
"phrases": 6,
91+
"words": 13
92+
}
93+
}
94+
],
95+
"skipped": {
96+
"translation_eq_source": 2,
97+
"qa_check": 1,
98+
"hidden_strings": 0,
99+
"ai_error": 6
100+
},
101+
"skippedQaCheckCategories": {
102+
"duplicate": 1,
103+
"spellcheck": 1
104+
}
105+
}
106+
],
107+
"preTranslateType": "ai"
108+
}
109+
}`)
110+
})
111+
112+
report, resp, err := client.Translations.PreTranslationReport(context.Background(), 1, "9e7de270-4f83-41cb-b606-2f90631f26e2")
113+
require.NoError(t, err)
114+
115+
expected := &model.PreTranslationReport{
116+
Languages: []*model.LanguageReport{
117+
{
118+
ID: "es",
119+
Files: []*model.LanguageReportFile{
120+
{
121+
ID: "10191",
122+
Statistics: &model.LanguageReportStatistics{
123+
Phrases: 6,
124+
Words: 13,
125+
},
126+
},
127+
},
128+
Skipped: &model.LanguageReportSkipped{
129+
TranslationEQSource: 2,
130+
QACheck: 1,
131+
HiddenStrings: 0,
132+
AIError: 6,
133+
},
134+
SkippedQaCheckCategories: &model.LanguageReportSkippedQaCheckCategories{
135+
Duplicate: 1,
136+
Spellcheck: 1,
137+
},
138+
},
139+
},
140+
PreTranslateType: "ai",
141+
}
142+
143+
assert.Equal(t, expected, report)
144+
assert.Equal(t, http.StatusOK, resp.StatusCode)
145+
}
146+
72147
func TestTranslationsService_ListPreTranslations(t *testing.T) {
73148
tests := []struct {
74149
name string

0 commit comments

Comments
 (0)