OLD | NEW |
(Empty) | |
| 1 library googleapis.translate.v2; |
| 2 |
| 3 import "dart:core" as core; |
| 4 import "dart:collection" as collection; |
| 5 import "dart:async" as async; |
| 6 import "dart:convert" as convert; |
| 7 |
| 8 import "package:crypto/crypto.dart" as crypto; |
| 9 import 'package:http/http.dart' as http; |
| 10 import '../src/common_internal.dart' as common_internal; |
| 11 import '../common/common.dart' as common; |
| 12 |
| 13 export '../common/common.dart' show ApiRequestError; |
| 14 export '../common/common.dart' show DetailedApiRequestError; |
| 15 |
| 16 /** Lets you translate text from one language to another */ |
| 17 class TranslateApi { |
| 18 |
| 19 final common_internal.ApiRequester _requester; |
| 20 |
| 21 DetectionsResourceApi get detections => new DetectionsResourceApi(_requester); |
| 22 LanguagesResourceApi get languages => new LanguagesResourceApi(_requester); |
| 23 TranslationsResourceApi get translations => new TranslationsResourceApi(_reque
ster); |
| 24 |
| 25 TranslateApi(http.Client client) : |
| 26 _requester = new common_internal.ApiRequester(client, "https://www.googlea
pis.com/", "/language/translate/"); |
| 27 } |
| 28 |
| 29 |
| 30 /** Not documented yet. */ |
| 31 class DetectionsResourceApi { |
| 32 final common_internal.ApiRequester _requester; |
| 33 |
| 34 DetectionsResourceApi(common_internal.ApiRequester client) : |
| 35 _requester = client; |
| 36 |
| 37 /** |
| 38 * Detect the language of text. |
| 39 * |
| 40 * Request parameters: |
| 41 * |
| 42 * [q] - The text to detect |
| 43 * |
| 44 * Completes with a [DetectionsListResponse]. |
| 45 * |
| 46 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 47 * error. |
| 48 * |
| 49 * If the used [http.Client] completes with an error when making a REST call, |
| 50 * this method will complete with the same error. |
| 51 */ |
| 52 async.Future<DetectionsListResponse> list(core.List<core.String> q) { |
| 53 var _url = null; |
| 54 var _queryParams = new core.Map(); |
| 55 var _uploadMedia = null; |
| 56 var _uploadOptions = null; |
| 57 var _downloadOptions = common.DownloadOptions.Metadata; |
| 58 var _body = null; |
| 59 |
| 60 if (q == null || q.isEmpty) { |
| 61 throw new core.ArgumentError("Parameter q is required."); |
| 62 } |
| 63 _queryParams["q"] = q; |
| 64 |
| 65 |
| 66 _url = 'v2/detect'; |
| 67 |
| 68 var _response = _requester.request(_url, |
| 69 "GET", |
| 70 body: _body, |
| 71 queryParams: _queryParams, |
| 72 uploadOptions: _uploadOptions, |
| 73 uploadMedia: _uploadMedia, |
| 74 downloadOptions: _downloadOptions); |
| 75 return _response.then((data) => new DetectionsListResponse.fromJson(data)); |
| 76 } |
| 77 |
| 78 } |
| 79 |
| 80 |
| 81 /** Not documented yet. */ |
| 82 class LanguagesResourceApi { |
| 83 final common_internal.ApiRequester _requester; |
| 84 |
| 85 LanguagesResourceApi(common_internal.ApiRequester client) : |
| 86 _requester = client; |
| 87 |
| 88 /** |
| 89 * List the source/target languages supported by the API |
| 90 * |
| 91 * Request parameters: |
| 92 * |
| 93 * [target] - the language and collation in which the localized results should |
| 94 * be returned |
| 95 * |
| 96 * Completes with a [LanguagesListResponse]. |
| 97 * |
| 98 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 99 * error. |
| 100 * |
| 101 * If the used [http.Client] completes with an error when making a REST call, |
| 102 * this method will complete with the same error. |
| 103 */ |
| 104 async.Future<LanguagesListResponse> list({core.String target}) { |
| 105 var _url = null; |
| 106 var _queryParams = new core.Map(); |
| 107 var _uploadMedia = null; |
| 108 var _uploadOptions = null; |
| 109 var _downloadOptions = common.DownloadOptions.Metadata; |
| 110 var _body = null; |
| 111 |
| 112 if (target != null) { |
| 113 _queryParams["target"] = [target]; |
| 114 } |
| 115 |
| 116 |
| 117 _url = 'v2/languages'; |
| 118 |
| 119 var _response = _requester.request(_url, |
| 120 "GET", |
| 121 body: _body, |
| 122 queryParams: _queryParams, |
| 123 uploadOptions: _uploadOptions, |
| 124 uploadMedia: _uploadMedia, |
| 125 downloadOptions: _downloadOptions); |
| 126 return _response.then((data) => new LanguagesListResponse.fromJson(data)); |
| 127 } |
| 128 |
| 129 } |
| 130 |
| 131 |
| 132 /** Not documented yet. */ |
| 133 class TranslationsResourceApi { |
| 134 final common_internal.ApiRequester _requester; |
| 135 |
| 136 TranslationsResourceApi(common_internal.ApiRequester client) : |
| 137 _requester = client; |
| 138 |
| 139 /** |
| 140 * Returns text translations from one language to another. |
| 141 * |
| 142 * Request parameters: |
| 143 * |
| 144 * [q] - The text to translate |
| 145 * |
| 146 * [target] - The target language into which the text should be translated |
| 147 * |
| 148 * [cid] - The customization id for translate |
| 149 * |
| 150 * [format] - The format of the text |
| 151 * Possible string values are: |
| 152 * - "html" : Specifies the input is in HTML |
| 153 * - "text" : Specifies the input is in plain textual format |
| 154 * |
| 155 * [source] - The source language of the text |
| 156 * |
| 157 * Completes with a [TranslationsListResponse]. |
| 158 * |
| 159 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 160 * error. |
| 161 * |
| 162 * If the used [http.Client] completes with an error when making a REST call, |
| 163 * this method will complete with the same error. |
| 164 */ |
| 165 async.Future<TranslationsListResponse> list(core.List<core.String> q, core.Str
ing target, {core.List<core.String> cid, core.String format, core.String source}
) { |
| 166 var _url = null; |
| 167 var _queryParams = new core.Map(); |
| 168 var _uploadMedia = null; |
| 169 var _uploadOptions = null; |
| 170 var _downloadOptions = common.DownloadOptions.Metadata; |
| 171 var _body = null; |
| 172 |
| 173 if (q == null || q.isEmpty) { |
| 174 throw new core.ArgumentError("Parameter q is required."); |
| 175 } |
| 176 _queryParams["q"] = q; |
| 177 if (target == null) { |
| 178 throw new core.ArgumentError("Parameter target is required."); |
| 179 } |
| 180 _queryParams["target"] = [target]; |
| 181 if (cid != null) { |
| 182 _queryParams["cid"] = cid; |
| 183 } |
| 184 if (format != null) { |
| 185 _queryParams["format"] = [format]; |
| 186 } |
| 187 if (source != null) { |
| 188 _queryParams["source"] = [source]; |
| 189 } |
| 190 |
| 191 |
| 192 _url = 'v2'; |
| 193 |
| 194 var _response = _requester.request(_url, |
| 195 "GET", |
| 196 body: _body, |
| 197 queryParams: _queryParams, |
| 198 uploadOptions: _uploadOptions, |
| 199 uploadMedia: _uploadMedia, |
| 200 downloadOptions: _downloadOptions); |
| 201 return _response.then((data) => new TranslationsListResponse.fromJson(data))
; |
| 202 } |
| 203 |
| 204 } |
| 205 |
| 206 |
| 207 |
| 208 /** Not documented yet. */ |
| 209 class DetectionsListResponse { |
| 210 /** A detections contains detection results of several text */ |
| 211 core.List<DetectionsResource> detections; |
| 212 |
| 213 |
| 214 DetectionsListResponse(); |
| 215 |
| 216 DetectionsListResponse.fromJson(core.Map _json) { |
| 217 if (_json.containsKey("detections")) { |
| 218 detections = _json["detections"].map((value) => new DetectionsResource.fro
mJson(value)).toList(); |
| 219 } |
| 220 } |
| 221 |
| 222 core.Map toJson() { |
| 223 var _json = new core.Map(); |
| 224 if (detections != null) { |
| 225 _json["detections"] = detections.map((value) => (value).toJson()).toList()
; |
| 226 } |
| 227 return _json; |
| 228 } |
| 229 } |
| 230 |
| 231 |
| 232 /** Not documented yet. */ |
| 233 class DetectionsResourceElement { |
| 234 /** The confidence of the detection resul of this language. */ |
| 235 core.double confidence; |
| 236 |
| 237 /** A boolean to indicate is the language detection result reliable. */ |
| 238 core.bool isReliable; |
| 239 |
| 240 /** The language we detect */ |
| 241 core.String language; |
| 242 |
| 243 |
| 244 DetectionsResourceElement(); |
| 245 |
| 246 DetectionsResourceElement.fromJson(core.Map _json) { |
| 247 if (_json.containsKey("confidence")) { |
| 248 confidence = _json["confidence"]; |
| 249 } |
| 250 if (_json.containsKey("isReliable")) { |
| 251 isReliable = _json["isReliable"]; |
| 252 } |
| 253 if (_json.containsKey("language")) { |
| 254 language = _json["language"]; |
| 255 } |
| 256 } |
| 257 |
| 258 core.Map toJson() { |
| 259 var _json = new core.Map(); |
| 260 if (confidence != null) { |
| 261 _json["confidence"] = confidence; |
| 262 } |
| 263 if (isReliable != null) { |
| 264 _json["isReliable"] = isReliable; |
| 265 } |
| 266 if (language != null) { |
| 267 _json["language"] = language; |
| 268 } |
| 269 return _json; |
| 270 } |
| 271 } |
| 272 |
| 273 |
| 274 /** |
| 275 * An array of languages which we detect for the given text The most likely |
| 276 * language list first. |
| 277 */ |
| 278 class DetectionsResource |
| 279 extends collection.ListBase<DetectionsResourceElement> { |
| 280 final core.List<DetectionsResourceElement> _inner; |
| 281 |
| 282 DetectionsResource() : _inner = []; |
| 283 |
| 284 DetectionsResource.fromJson(core.List json) |
| 285 : _inner = json.map((value) => new DetectionsResourceElement.fromJson(valu
e)).toList(); |
| 286 |
| 287 core.List toJson() { |
| 288 return _inner.map((value) => (value).toJson()).toList(); |
| 289 } |
| 290 |
| 291 DetectionsResourceElement operator [](core.int key) => _inner[key]; |
| 292 |
| 293 void operator []=(core.int key, DetectionsResourceElement value) { |
| 294 _inner[key] = value; |
| 295 } |
| 296 |
| 297 core.int get length => _inner.length; |
| 298 |
| 299 void set length(core.int newLength) { |
| 300 _inner.length = newLength; |
| 301 } |
| 302 } |
| 303 |
| 304 |
| 305 /** Not documented yet. */ |
| 306 class LanguagesListResponse { |
| 307 /** |
| 308 * List of source/target languages supported by the translation API. If target |
| 309 * parameter is unspecified, the list is sorted by the ASCII code point order |
| 310 * of the language code. If target parameter is specified, the list is sorted |
| 311 * by the collation order of the language name in the target language. |
| 312 */ |
| 313 core.List<LanguagesResource> languages; |
| 314 |
| 315 |
| 316 LanguagesListResponse(); |
| 317 |
| 318 LanguagesListResponse.fromJson(core.Map _json) { |
| 319 if (_json.containsKey("languages")) { |
| 320 languages = _json["languages"].map((value) => new LanguagesResource.fromJs
on(value)).toList(); |
| 321 } |
| 322 } |
| 323 |
| 324 core.Map toJson() { |
| 325 var _json = new core.Map(); |
| 326 if (languages != null) { |
| 327 _json["languages"] = languages.map((value) => (value).toJson()).toList(); |
| 328 } |
| 329 return _json; |
| 330 } |
| 331 } |
| 332 |
| 333 |
| 334 /** Not documented yet. */ |
| 335 class LanguagesResource { |
| 336 /** The language code. */ |
| 337 core.String language; |
| 338 |
| 339 /** The localized name of the language if target parameter is given. */ |
| 340 core.String name; |
| 341 |
| 342 |
| 343 LanguagesResource(); |
| 344 |
| 345 LanguagesResource.fromJson(core.Map _json) { |
| 346 if (_json.containsKey("language")) { |
| 347 language = _json["language"]; |
| 348 } |
| 349 if (_json.containsKey("name")) { |
| 350 name = _json["name"]; |
| 351 } |
| 352 } |
| 353 |
| 354 core.Map toJson() { |
| 355 var _json = new core.Map(); |
| 356 if (language != null) { |
| 357 _json["language"] = language; |
| 358 } |
| 359 if (name != null) { |
| 360 _json["name"] = name; |
| 361 } |
| 362 return _json; |
| 363 } |
| 364 } |
| 365 |
| 366 |
| 367 /** Not documented yet. */ |
| 368 class TranslationsListResponse { |
| 369 /** Translations contains list of translation results of given text */ |
| 370 core.List<TranslationsResource> translations; |
| 371 |
| 372 |
| 373 TranslationsListResponse(); |
| 374 |
| 375 TranslationsListResponse.fromJson(core.Map _json) { |
| 376 if (_json.containsKey("translations")) { |
| 377 translations = _json["translations"].map((value) => new TranslationsResour
ce.fromJson(value)).toList(); |
| 378 } |
| 379 } |
| 380 |
| 381 core.Map toJson() { |
| 382 var _json = new core.Map(); |
| 383 if (translations != null) { |
| 384 _json["translations"] = translations.map((value) => (value).toJson()).toLi
st(); |
| 385 } |
| 386 return _json; |
| 387 } |
| 388 } |
| 389 |
| 390 |
| 391 /** Not documented yet. */ |
| 392 class TranslationsResource { |
| 393 /** Detected source language if source parameter is unspecified. */ |
| 394 core.String detectedSourceLanguage; |
| 395 |
| 396 /** The translation. */ |
| 397 core.String translatedText; |
| 398 |
| 399 |
| 400 TranslationsResource(); |
| 401 |
| 402 TranslationsResource.fromJson(core.Map _json) { |
| 403 if (_json.containsKey("detectedSourceLanguage")) { |
| 404 detectedSourceLanguage = _json["detectedSourceLanguage"]; |
| 405 } |
| 406 if (_json.containsKey("translatedText")) { |
| 407 translatedText = _json["translatedText"]; |
| 408 } |
| 409 } |
| 410 |
| 411 core.Map toJson() { |
| 412 var _json = new core.Map(); |
| 413 if (detectedSourceLanguage != null) { |
| 414 _json["detectedSourceLanguage"] = detectedSourceLanguage; |
| 415 } |
| 416 if (translatedText != null) { |
| 417 _json["translatedText"] = translatedText; |
| 418 } |
| 419 return _json; |
| 420 } |
| 421 } |
| 422 |
| 423 |
OLD | NEW |