diff --git a/DOCS.md b/DOCS.md index a6c411b..dfdb101 100644 --- a/DOCS.md +++ b/DOCS.md @@ -2,8 +2,8 @@ Use the Crowdin plugin to update translation files. You must provide in your configuration: -* `project-identifier` - Identifier of your Crowdin project -* `project-key` - API Key of your Crowdin project +* `project_identifier` - Identifier of your Crowdin project +* `project_key` - API Key of your Crowdin project * `files` - Map of files with the crowdin file name as key and the to-upload file-path as value. Information about API keys: https://support.crowdin.com/api/api-integration-setup/ @@ -14,8 +14,8 @@ The following is a sample configuration in your .drone.yml file: ```yaml translations: crowdin: - project-identifier: example - project-key: 1bc29b36f623ba82aaf6724fd3b16718 + project_identifier: example + project_key: 1bc29b36f623ba82aaf6724fd3b16718 files: example: options/example.ini example2: options/example2.ini diff --git a/main.go b/main.go index 4f33eb6..d4b4a7d 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,6 @@ func main() { } if err := app.Run(os.Args); err != nil { log.Fatal(err) - os.Exit(1) } } diff --git a/plugin.go b/plugin.go index 4d77255..21f73dd 100644 --- a/plugin.go +++ b/plugin.go @@ -31,6 +31,7 @@ func (c Config) ToURL() string { } func (p Plugin) Exec() error { + p.Files = map[string]string{"locale_en-US.ini": "DOCS.md"} if len(p.Files) > 20 { return fmt.Errorf("20 files max are allowed to upload. %d files given", len(p.Files)) } @@ -84,6 +85,16 @@ func (p Plugin) Exec() error { return err } return err_response + } else { + var success = new(responses.Success) + decoder := xml.NewDecoder(body) + decoder.CharsetReader = charset.NewReaderLabel + if err := decoder.Decode(&success); err != nil { + return err + } + for _, file := range success.Stats { + fmt.Printf("%s: %s\n", file.Name, file.Status) + } } return nil } diff --git a/responses/responses.go b/responses/responses.go index 981de66..7aaaa83 100644 --- a/responses/responses.go +++ b/responses/responses.go @@ -14,3 +14,14 @@ type Error struct { func (e *Error) Error() string { return fmt.Sprintf("Error from crowdin: %s (error code %d)", e.Message, e.Code) } + +type Success struct { + XMLName xml.Name `xml:"success"` + Stats []File `xml:"stats>file"` +} + +type File struct { + XMLName xml.Name `xml:"file"` + Name string `xml:"name,attr"` + Status string `xml:"status,attr"` +}