@@ 18-107 (lines=90) @@ | ||
15 | * |
|
16 | * @since 1.0.5 |
|
17 | */ |
|
18 | Class Glossary extends Package |
|
19 | { |
|
20 | /** |
|
21 | * Download Crowdin project glossaries as TBX file. |
|
22 | * |
|
23 | * @param boolean $includeAssigned Defines whether the assigned glossaries should be included in downloaded TBX file. |
|
24 | * Acceptable values are: 0, 1. |
|
25 | * Default is 1. |
|
26 | * |
|
27 | * @since 1.0.5 |
|
28 | * @see https://crowdin.com/page/api/download-glossary |
|
29 | * |
|
30 | * @return \Psr\Http\Message\ResponseInterface |
|
31 | */ |
|
32 | public function download($includeAssigned = true) |
|
33 | { |
|
34 | return $this->getHttpClient() |
|
35 | ->get($this->getBasePath('download-glossary') . '&include_assigned=' . (int) $includeAssigned); |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Upload your Translation Memory for Crowdin Project in TMX file format. |
|
40 | * |
|
41 | * @param string $file Full path to file to upload. |
|
42 | * |
|
43 | * @since 1.0.5 |
|
44 | * @see https://crowdin.com/page/api/upload-glossary |
|
45 | * |
|
46 | * @return string |
|
47 | */ |
|
48 | public function upload($file) |
|
49 | { |
|
50 | if (false === file_exists($file)) |
|
51 | { |
|
52 | throw new \UnexpectedValueException('File not found for upload'); |
|
53 | } |
|
54 | ||
55 | /* |
|
56 | * @todo Crowdin does not accept Guzzle's POST requests. |
|
57 | * She just tells me: |
|
58 | * <code>4</code> |
|
59 | * <message>No files specified in request</message> |
|
60 | * |
|
61 | * :( |
|
62 | ||
63 | return $this->getHttpClient() |
|
64 | ->post($this->getBasePath('upload-glossary'), ['form_params' => ['file' => $file]]); |
|
65 | ||
66 | HELP WANTED !!! |
|
67 | ||
68 | */ |
|
69 | ||
70 | $post_params = array(); |
|
71 | $request_url = 'https://api.crowdin.com/api/' . $this->getBasePath('upload-glossary'); |
|
72 | ||
73 | if (function_exists('curl_file_create')) |
|
74 | { |
|
75 | $post_params['file'] = curl_file_create($file); |
|
76 | } |
|
77 | else |
|
78 | { |
|
79 | /* |
|
80 | * This does NOT seem to work with Mrs. Crowdin... |
|
81 | * ... comes from their docs |
|
82 | * $post_params['file'] = '@/home/crowdin/test.tmx'; |
|
83 | */ |
|
84 | throw new \RuntimeException('This version of cURL does not seem to work (with Crowdin...)'); |
|
85 | } |
|
86 | ||
87 | $ch = curl_init(); |
|
88 | ||
89 | curl_setopt($ch, CURLOPT_URL, $request_url); |
|
90 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
91 | curl_setopt($ch, CURLOPT_POST, true); |
|
92 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params); |
|
93 | ||
94 | $result = curl_exec($ch); |
|
95 | ||
96 | curl_close($ch); |
|
97 | ||
98 | if (false === $result) |
|
99 | { |
|
100 | throw new \UnexpectedValueException('File upload failed'); |
|
101 | ||
102 | // @todo Some more errors pls.... |
|
103 | } |
|
104 | ||
105 | return 'File has been uploaded (?)'; |
|
106 | } |
|
107 | } |
|
108 |
@@ 18-107 (lines=90) @@ | ||
15 | * |
|
16 | * @since 1.0.5 |
|
17 | */ |
|
18 | Class Memory extends Package |
|
19 | { |
|
20 | /** |
|
21 | * Download Crowdin project Translation Memory as TMX file. |
|
22 | * |
|
23 | * @param boolean $includeAssigned Defines whether the assigned TMs should be included in downloaded TMX file. |
|
24 | * Acceptable values are: 0, 1. |
|
25 | * Default is 1. |
|
26 | * |
|
27 | * @since 1.0.5 |
|
28 | * @see https://crowdin.com/page/api/download-tm |
|
29 | * |
|
30 | * @return \Psr\Http\Message\ResponseInterface |
|
31 | */ |
|
32 | public function download($includeAssigned = true) |
|
33 | { |
|
34 | return $this->getHttpClient() |
|
35 | ->get($this->getBasePath('download-tm') . '&include_assigned=' . (int) $includeAssigned); |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Upload your Translation Memory for Crowdin Project in TMX file format. |
|
40 | * |
|
41 | * @param string $file Full path to file to upload. |
|
42 | * |
|
43 | * @since 1.0.5 |
|
44 | * @see https://crowdin.com/page/api/upload-tm |
|
45 | * |
|
46 | * @return string |
|
47 | */ |
|
48 | public function upload($file) |
|
49 | { |
|
50 | if (false === file_exists($file)) |
|
51 | { |
|
52 | throw new \UnexpectedValueException('File not found for upload'); |
|
53 | } |
|
54 | ||
55 | /* |
|
56 | * @todo Crowdin does not accept Guzzle's POST requests. |
|
57 | * She just tells me: |
|
58 | * <code>4</code> |
|
59 | * <message>No files specified in request</message> |
|
60 | * |
|
61 | * :( |
|
62 | ||
63 | return $this->getHttpClient() |
|
64 | ->post($this->getBasePath('upload-tm'), ['form_params' => ['file' => $file]]); |
|
65 | ||
66 | HELP WANTED !!! |
|
67 | ||
68 | */ |
|
69 | ||
70 | $post_params = array(); |
|
71 | $request_url = 'https://api.crowdin.com/api/' . $this->getBasePath('upload-tm'); |
|
72 | ||
73 | if (function_exists('curl_file_create')) |
|
74 | { |
|
75 | $post_params['file'] = curl_file_create($file); |
|
76 | } |
|
77 | else |
|
78 | { |
|
79 | /* |
|
80 | * This does NOT seem to work with Mrs. Crowdin... |
|
81 | * ... comes from their docs |
|
82 | * $post_params['file'] = '@/home/crowdin/test.tmx'; |
|
83 | */ |
|
84 | throw new \RuntimeException('This version of cURL does not seem to work (with Crowdin...)'); |
|
85 | } |
|
86 | ||
87 | $ch = curl_init(); |
|
88 | ||
89 | curl_setopt($ch, CURLOPT_URL, $request_url); |
|
90 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
91 | curl_setopt($ch, CURLOPT_POST, true); |
|
92 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params); |
|
93 | ||
94 | $result = curl_exec($ch); |
|
95 | ||
96 | curl_close($ch); |
|
97 | ||
98 | if (false === $result) |
|
99 | { |
|
100 | throw new \UnexpectedValueException('File upload failed'); |
|
101 | ||
102 | // @todo Some more errors pls.... |
|
103 | } |
|
104 | ||
105 | return 'File has been uploaded (?)'; |
|
106 | } |
|
107 | } |
|
108 |