PluginProbe
Gianism / 1.1
Gianism v1.1
4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.4.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.1 5.2.2 5.3.0 6.0.0 6.0.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 65 releases
gianism / sdks / google / contrib / apiTranslateService.php

apiTranslateService.php in Gianism 1.1, at sdks/google/contrib/apiTranslateService.php

255 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Copyright (c) 2010 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy of
7 * the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18 require_once 'service/apiModel.php';
19 require_once 'service/apiService.php';
20 require_once 'service/apiServiceRequest.php';
21
22
23 /**
24 * The "languages" collection of methods.
25 * Typical usage is:
26 * <code>
27 * $translateService = new apiTranslateService(...);
28 * $languages = $translateService->languages;
29 * </code>
30 */
31 class LanguagesServiceResource extends apiServiceResource {
32
33
34 /**
35 * List the source/target languages supported by the API (languages.list)
36 *
37 * @param array $optParams Optional parameters. Valid optional parameters are listed below.
38 *
39 * @opt_param string target the language and collation in which the localized results should be returned
40 * @return LanguagesListResponse
41 */
42 public function listLanguages($optParams = array()) {
43 $params = array();
44 $params = array_merge($params, $optParams);
45 $data = $this->__call('list', array($params));
46 if ($this->useObjects()) {
47 return new LanguagesListResponse($data);
48 } else {
49 return $data;
50 }
51 }
52 }
53
54 /**
55 * The "detections" collection of methods.
56 * Typical usage is:
57 * <code>
58 * $translateService = new apiTranslateService(...);
59 * $detections = $translateService->detections;
60 * </code>
61 */
62 class DetectionsServiceResource extends apiServiceResource {
63
64
65 /**
66 * Detect the language of text. (detections.list)
67 *
68 * @param string $q The text to detect
69 * @return DetectionsListResponse
70 */
71 public function listDetections($q, $optParams = array()) {
72 $params = array('q' => $q);
73 $params = array_merge($params, $optParams);
74 $data = $this->__call('list', array($params));
75 if ($this->useObjects()) {
76 return new DetectionsListResponse($data);
77 } else {
78 return $data;
79 }
80 }
81 }
82
83 /**
84 * The "translations" collection of methods.
85 * Typical usage is:
86 * <code>
87 * $translateService = new apiTranslateService(...);
88 * $translations = $translateService->translations;
89 * </code>
90 */
91 class TranslationsServiceResource extends apiServiceResource {
92
93
94 /**
95 * Returns text translations from one language to another. (translations.list)
96 *
97 * @param string $q The text to translate
98 * @param string $target The target language into which the text should be translated
99 * @param array $optParams Optional parameters. Valid optional parameters are listed below.
100 *
101 * @opt_param string source The source language of the text
102 * @opt_param string format The format of the text
103 * @opt_param string cid The customization id for translate
104 * @return TranslationsListResponse
105 */
106 public function listTranslations($q, $target, $optParams = array()) {
107 $params = array('q' => $q, 'target' => $target);
108 $params = array_merge($params, $optParams);
109 $data = $this->__call('list', array($params));
110 if ($this->useObjects()) {
111 return new TranslationsListResponse($data);
112 } else {
113 return $data;
114 }
115 }
116 }
117
118
119
120 /**
121 * Service definition for Translate (v2).
122 *
123 * <p>
124 * Lets you translate text from one language to another
125 * </p>
126 *
127 * <p>
128 * For more information about this service, see the
129 * <a href="http://code.google.com/apis/language/translate/v2/using_rest.html" target="_blank">API Documentation</a>
130 * </p>
131 *
132 * @author Google, Inc.
133 */
134 class apiTranslateService extends apiService {
135 public $languages;
136 public $detections;
137 public $translations;
138 /**
139 * Constructs the internal representation of the Translate service.
140 *
141 * @param apiClient apiClient
142 */
143 public function __construct(apiClient $apiClient) {
144 $this->rpcPath = '/rpc';
145 $this->restBasePath = '/language/translate/';
146 $this->version = 'v2';
147 $this->serviceName = 'translate';
148
149 $apiClient->addService($this->serviceName, $this->version);
150 $this->languages = new LanguagesServiceResource($this, $this->serviceName, 'languages', json_decode('{"methods": {"list": {"parameters": {"target": {"type": "string", "location": "query"}}, "id": "language.languages.list", "httpMethod": "GET", "path": "v2/languages", "response": {"$ref": "LanguagesListResponse"}}}}', true));
151 $this->detections = new DetectionsServiceResource($this, $this->serviceName, 'detections', json_decode('{"methods": {"list": {"parameters": {"q": {"repeated": true, "required": true, "type": "string", "location": "query"}}, "id": "language.detections.list", "httpMethod": "GET", "path": "v2/detect", "response": {"$ref": "DetectionsListResponse"}}}}', true));
152 $this->translations = new TranslationsServiceResource($this, $this->serviceName, 'translations', json_decode('{"methods": {"list": {"parameters": {"q": {"repeated": true, "required": true, "type": "string", "location": "query"}, "source": {"type": "string", "location": "query"}, "cid": {"repeated": true, "type": "string", "location": "query"}, "target": {"required": true, "type": "string", "location": "query"}, "format": {"enum": ["html", "text"], "type": "string", "location": "query"}}, "id": "language.translations.list", "httpMethod": "GET", "path": "v2", "response": {"$ref": "TranslationsListResponse"}}}}', true));
153 }
154 }
155
156 class DetectionsListResponse extends apiModel {
157 protected $__detectionsType = 'DetectionsResourceItems';
158 protected $__detectionsDataType = 'array';
159 public $detections;
160 public function setDetections(/* array(DetectionsResourceItems) */ $detections) {
161 $this->assertIsArray($detections, 'DetectionsResourceItems', __METHOD__);
162 $this->detections = $detections;
163 }
164 public function getDetections() {
165 return $this->detections;
166 }
167 }
168
169 class DetectionsResource extends apiModel {
170 }
171
172 class DetectionsResourceItems extends apiModel {
173 public $isReliable;
174 public $confidence;
175 public $language;
176 public function setIsReliable($isReliable) {
177 $this->isReliable = $isReliable;
178 }
179 public function getIsReliable() {
180 return $this->isReliable;
181 }
182 public function setConfidence($confidence) {
183 $this->confidence = $confidence;
184 }
185 public function getConfidence() {
186 return $this->confidence;
187 }
188 public function setLanguage($language) {
189 $this->language = $language;
190 }
191 public function getLanguage() {
192 return $this->language;
193 }
194 }
195
196 class LanguagesListResponse extends apiModel {
197 protected $__languagesType = 'LanguagesResource';
198 protected $__languagesDataType = 'array';
199 public $languages;
200 public function setLanguages(/* array(LanguagesResource) */ $languages) {
201 $this->assertIsArray($languages, 'LanguagesResource', __METHOD__);
202 $this->languages = $languages;
203 }
204 public function getLanguages() {
205 return $this->languages;
206 }
207 }
208
209 class LanguagesResource extends apiModel {
210 public $name;
211 public $language;
212 public function setName($name) {
213 $this->name = $name;
214 }
215 public function getName() {
216 return $this->name;
217 }
218 public function setLanguage($language) {
219 $this->language = $language;
220 }
221 public function getLanguage() {
222 return $this->language;
223 }
224 }
225
226 class TranslationsListResponse extends apiModel {
227 protected $__translationsType = 'TranslationsResource';
228 protected $__translationsDataType = 'array';
229 public $translations;
230 public function setTranslations(/* array(TranslationsResource) */ $translations) {
231 $this->assertIsArray($translations, 'TranslationsResource', __METHOD__);
232 $this->translations = $translations;
233 }
234 public function getTranslations() {
235 return $this->translations;
236 }
237 }
238
239 class TranslationsResource extends apiModel {
240 public $detectedSourceLanguage;
241 public $translatedText;
242 public function setDetectedSourceLanguage($detectedSourceLanguage) {
243 $this->detectedSourceLanguage = $detectedSourceLanguage;
244 }
245 public function getDetectedSourceLanguage() {
246 return $this->detectedSourceLanguage;
247 }
248 public function setTranslatedText($translatedText) {
249 $this->translatedText = $translatedText;
250 }
251 public function getTranslatedText() {
252 return $this->translatedText;
253 }
254 }
255