|
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 Translation Strings class. |
|
10
|
|
|
* |
|
11
|
|
|
* @link http://docs.transifex.com/api/translation_strings/ |
|
12
|
|
|
*/ |
|
13
|
|
|
final class Translationstrings extends ApiConnector |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Method to get pseudolocalization strings 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
|
|
|
* |
|
21
|
|
|
* @return ResponseInterface |
|
22
|
|
|
*/ |
|
23
|
2 |
|
public function getPseudolocalizationStrings(string $project, string $resource): ResponseInterface |
|
24
|
|
|
{ |
|
25
|
2 |
|
return $this->client->sendRequest($this->createRequest('GET', $this->createUri("/api/2/project/$project/resource/$resource/pseudo/?pseudo_type=MIXED"))); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Method to get the translation strings on a specified resource. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $project The slug for the project to pull from |
|
32
|
|
|
* @param string $resource The slug for the resource to pull from |
|
33
|
|
|
* @param string $lang The language to return the translation for |
|
34
|
|
|
* @param bool $details Flag to retrieve additional details on the strings |
|
35
|
|
|
* @param array $options An array of additional options for the request |
|
36
|
|
|
* |
|
37
|
|
|
* @return ResponseInterface |
|
38
|
|
|
*/ |
|
39
|
7 |
|
public function getStrings( |
|
40
|
|
|
string $project, |
|
41
|
|
|
string $resource, |
|
42
|
|
|
string $lang, |
|
43
|
|
|
bool $details = false, |
|
44
|
|
|
array $options = [] |
|
45
|
|
|
): ResponseInterface { |
|
46
|
7 |
|
$uri = $this->createUri("/api/2/project/$project/resource/$resource/translation/$lang/strings/"); |
|
47
|
7 |
|
$query = []; |
|
48
|
|
|
|
|
49
|
7 |
|
if ($details) { |
|
50
|
|
|
// Add details now because `http_build_query()` can't handle something that isn't a key/value pair |
|
51
|
3 |
|
$uri = $uri->withQuery('details'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
7 |
|
if (isset($options['key'])) { |
|
55
|
3 |
|
$query['key'] = $options['key']; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
7 |
|
if (isset($options['context'])) { |
|
59
|
3 |
|
$query['context'] = $options['context']; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
7 |
|
if (!empty($query)) { |
|
63
|
4 |
|
if ($uri->getQuery() === '') { |
|
64
|
2 |
|
$uri = $uri->withQuery(\http_build_query($query)); |
|
65
|
|
|
} else { |
|
66
|
2 |
|
$uri = $uri->withQuery($uri->getQuery() . '&' . \http_build_query($query)); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
7 |
|
return $this->client->sendRequest($this->createRequest('GET', $uri)); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|