Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
40 changes: 40 additions & 0 deletions crowdin/model/translations.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,40 @@ type (
TranslateUntranslatedOnly *bool `json:"translateUntranslatedOnly,omitempty"`
TranslateWithPerfectMatchOnly *bool `json:"translateWithPerfectMatchOnly,omitempty"`
}

PreTranslationReport struct {
Languages []*LanguageReport `json:"languages"`
PreTranslateType string `json:"preTranslateType"`
}

LanguageReport struct {
ID string `json:"id"`
Files []*LanguageReportFile `json:"files"`
Skipped *LanguageReportSkipped `json:"skipped,omitempty"`
SkippedQaCheckCategories *LanguageReportSkippedQaCheckCategories `json:"skippedQaCheckCategories,omitempty"`
}

LanguageReportFile struct {
ID string `json:"id"`
Statistics *LanguageReportStatistics `json:"statistics"`
}

LanguageReportStatistics struct {
Phrases int `json:"phrases"`
Words int `json:"words"`
}

LanguageReportSkipped struct {
TranslationEQSource int `json:"translation_eq_source"`
QACheck int `json:"qa_check"`
HiddenStrings int `json:"hidden_strings"`
AIError int `json:"ai_error"`
}

LanguageReportSkippedQaCheckCategories struct {
Duplicate int `json:"duplicate"`
Spellcheck int `json:"spellcheck"`
}
)

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

// PreTranslationReportResponse defines the structure of a response when
// getting a pre-translation report.
type PreTranslationReportResponse struct {
Data *PreTranslationReport `json:"data"`
}

// PreTranslationRequest defines the structure of a request to apply pre-translation.
type PreTranslationRequest struct {
// Set of languages to which pre-translation should be applied.
Expand Down
12 changes: 12 additions & 0 deletions crowdin/translations.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ func (s *TranslationsService) ApplyPreTranslation(ctx context.Context, projectID
return res.Data, resp, err
}

// PreTranslationReport returns report data for a specific pre-translation.
//
// https://support.crowdin.com/developer/api/v2/#tag/Translations/operation/api.projects.pre-translations.report.getReport
func (s *TranslationsService) PreTranslationReport(
ctx context.Context, projectID int, preTranslationID string,
) (*model.PreTranslationReport, *Response, error) {
res := new(model.PreTranslationReportResponse)
resp, err := s.client.Get(ctx, fmt.Sprintf("/api/v2/projects/%d/pre-translations/%s/reports", projectID, preTranslationID), nil, res)

return res.Data, resp, err
}

// BuildProjectDirectoryTranslation builds translations for a specific directory in the project.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.directories.post
Expand Down
75 changes: 75 additions & 0 deletions crowdin/translations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,81 @@ func TestTranslationsService_PreTranslationStatus(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestTranslationsService_PreTranslationReport(t *testing.T) {
client, mux, teardown := setupClient()
defer teardown()

const path = "/api/v2/projects/1/pre-translations/9e7de270-4f83-41cb-b606-2f90631f26e2/reports"
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testURL(t, r, path)

fmt.Fprint(w, `{
"data": {
"languages": [
{
"id": "es",
"files": [
{
"id": "10191",
"statistics": {
"phrases": 6,
"words": 13
}
}
],
"skipped": {
"translation_eq_source": 2,
"qa_check": 1,
"hidden_strings": 0,
"ai_error": 6
},
"skippedQaCheckCategories": {
"duplicate": 1,
"spellcheck": 1
}
}
],
"preTranslateType": "ai"
}
}`)
})

report, resp, err := client.Translations.PreTranslationReport(context.Background(), 1, "9e7de270-4f83-41cb-b606-2f90631f26e2")
require.NoError(t, err)

expected := &model.PreTranslationReport{
Languages: []*model.LanguageReport{
{
ID: "es",
Files: []*model.LanguageReportFile{
{
ID: "10191",
Statistics: &model.LanguageReportStatistics{
Phrases: 6,
Words: 13,
},
},
},
Skipped: &model.LanguageReportSkipped{
TranslationEQSource: 2,
QACheck: 1,
HiddenStrings: 0,
AIError: 6,
},
SkippedQaCheckCategories: &model.LanguageReportSkippedQaCheckCategories{
Duplicate: 1,
Spellcheck: 1,
},
},
},
PreTranslateType: "ai",
}

assert.Equal(t, expected, report)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestTranslationsService_ListPreTranslations(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading