|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace BabDev\Transifex\Connector; |
|
4
|
|
|
|
|
5
|
|
|
use BabDev\Transifex\ApiConnector; |
|
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Transifex API Translations class. |
|
10
|
|
|
* |
|
11
|
|
|
* @link http://docs.transifex.com/api/translations/ |
|
12
|
|
|
*/ |
|
13
|
|
|
final class Translations extends ApiConnector |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Get translations on a specified resource. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $project The slug for the project to pull from |
|
19
|
|
|
* @param string $resource The slug for the resource to pull from |
|
20
|
|
|
* @param string $lang The language to return the translation for |
|
21
|
|
|
* @param string $mode The mode of the downloaded file |
|
22
|
|
|
* |
|
23
|
|
|
* @return ResponseInterface |
|
24
|
|
|
*/ |
|
25
|
2 |
|
public function getTranslation( |
|
26
|
|
|
string $project, |
|
27
|
|
|
string $resource, |
|
28
|
|
|
string $lang, |
|
29
|
|
|
string $mode = '' |
|
30
|
|
|
): ResponseInterface { |
|
31
|
2 |
|
$uri = $this->createUri("/api/2/project/$project/resource/$resource/translation/$lang"); |
|
32
|
|
|
|
|
33
|
2 |
|
if (!empty($mode)) { |
|
34
|
2 |
|
$uri = $uri->withQuery("mode=$mode&file"); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
return $this->client->sendRequest($this->createRequest('GET', $uri)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Update the content of a translation within a project. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $project The project the resource is part of |
|
44
|
|
|
* @param string $resource The resource slug within the project |
|
45
|
|
|
* @param string $lang The language to return the translation for |
|
46
|
|
|
* @param string $content The content of the resource, this can either be a string of data or a file path |
|
47
|
|
|
* @param string $type The type of content in the $content variable, this should be either string or file |
|
48
|
|
|
* |
|
49
|
|
|
* @return ResponseInterface |
|
50
|
|
|
*/ |
|
51
|
5 |
|
public function updateTranslation( |
|
52
|
|
|
string $project, |
|
53
|
|
|
string $resource, |
|
54
|
|
|
string $lang, |
|
55
|
|
|
string $content, |
|
56
|
|
|
string $type = 'string' |
|
57
|
|
|
): ResponseInterface { |
|
58
|
5 |
|
return $this->updateResource( |
|
59
|
5 |
|
$this->createUri("/api/2/project/$project/resource/$resource/translation/$lang"), |
|
60
|
5 |
|
$content, |
|
61
|
5 |
|
$type |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|