Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

1204 righe
41 KiB

  1. // Package translate provides access to the Google Cloud Translation API.
  2. //
  3. // See https://code.google.com/apis/language/translate/v2/getting_started.html
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/translate/v2"
  8. // ...
  9. // translateService, err := translate.New(oauthHttpClient)
  10. package translate // import "google.golang.org/api/translate/v2"
  11. import (
  12. "bytes"
  13. "encoding/json"
  14. "errors"
  15. "fmt"
  16. context "golang.org/x/net/context"
  17. ctxhttp "golang.org/x/net/context/ctxhttp"
  18. gensupport "google.golang.org/api/gensupport"
  19. googleapi "google.golang.org/api/googleapi"
  20. "io"
  21. "net/http"
  22. "net/url"
  23. "strconv"
  24. "strings"
  25. )
  26. // Always reference these packages, just in case the auto-generated code
  27. // below doesn't.
  28. var _ = bytes.NewBuffer
  29. var _ = strconv.Itoa
  30. var _ = fmt.Sprintf
  31. var _ = json.NewDecoder
  32. var _ = io.Copy
  33. var _ = url.Parse
  34. var _ = gensupport.MarshalJSON
  35. var _ = googleapi.Version
  36. var _ = errors.New
  37. var _ = strings.Replace
  38. var _ = context.Canceled
  39. var _ = ctxhttp.Do
  40. const apiId = "translate:v2"
  41. const apiName = "translate"
  42. const apiVersion = "v2"
  43. const basePath = "https://translation.googleapis.com/language/translate/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // View and manage your data across Google Cloud Platform services
  47. CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
  48. // Translate text from one language to another using Google Translate
  49. CloudTranslationScope = "https://www.googleapis.com/auth/cloud-translation"
  50. )
  51. func New(client *http.Client) (*Service, error) {
  52. if client == nil {
  53. return nil, errors.New("client is nil")
  54. }
  55. s := &Service{client: client, BasePath: basePath}
  56. s.Detections = NewDetectionsService(s)
  57. s.Languages = NewLanguagesService(s)
  58. s.Translations = NewTranslationsService(s)
  59. return s, nil
  60. }
  61. type Service struct {
  62. client *http.Client
  63. BasePath string // API endpoint base URL
  64. UserAgent string // optional additional User-Agent fragment
  65. Detections *DetectionsService
  66. Languages *LanguagesService
  67. Translations *TranslationsService
  68. }
  69. func (s *Service) userAgent() string {
  70. if s.UserAgent == "" {
  71. return googleapi.UserAgent
  72. }
  73. return googleapi.UserAgent + " " + s.UserAgent
  74. }
  75. func NewDetectionsService(s *Service) *DetectionsService {
  76. rs := &DetectionsService{s: s}
  77. return rs
  78. }
  79. type DetectionsService struct {
  80. s *Service
  81. }
  82. func NewLanguagesService(s *Service) *LanguagesService {
  83. rs := &LanguagesService{s: s}
  84. return rs
  85. }
  86. type LanguagesService struct {
  87. s *Service
  88. }
  89. func NewTranslationsService(s *Service) *TranslationsService {
  90. rs := &TranslationsService{s: s}
  91. return rs
  92. }
  93. type TranslationsService struct {
  94. s *Service
  95. }
  96. // DetectLanguageRequest: The request message for language detection.
  97. type DetectLanguageRequest struct {
  98. // Q: The input text upon which to perform language detection. Repeat
  99. // this
  100. // parameter to perform language detection on multiple text inputs.
  101. Q []string `json:"q,omitempty"`
  102. // ForceSendFields is a list of field names (e.g. "Q") to
  103. // unconditionally include in API requests. By default, fields with
  104. // empty values are omitted from API requests. However, any non-pointer,
  105. // non-interface field appearing in ForceSendFields will be sent to the
  106. // server regardless of whether the field is empty or not. This may be
  107. // used to include empty fields in Patch requests.
  108. ForceSendFields []string `json:"-"`
  109. // NullFields is a list of field names (e.g. "Q") to include in API
  110. // requests with the JSON null value. By default, fields with empty
  111. // values are omitted from API requests. However, any field with an
  112. // empty value appearing in NullFields will be sent to the server as
  113. // null. It is an error if a field in this list has a non-empty value.
  114. // This may be used to include null fields in Patch requests.
  115. NullFields []string `json:"-"`
  116. }
  117. func (s *DetectLanguageRequest) MarshalJSON() ([]byte, error) {
  118. type NoMethod DetectLanguageRequest
  119. raw := NoMethod(*s)
  120. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  121. }
  122. type DetectionsListResponse struct {
  123. // Detections: A detections contains detection results of several text
  124. Detections [][]*DetectionsResourceItem `json:"detections,omitempty"`
  125. // ServerResponse contains the HTTP response code and headers from the
  126. // server.
  127. googleapi.ServerResponse `json:"-"`
  128. // ForceSendFields is a list of field names (e.g. "Detections") to
  129. // unconditionally include in API requests. By default, fields with
  130. // empty values are omitted from API requests. However, any non-pointer,
  131. // non-interface field appearing in ForceSendFields will be sent to the
  132. // server regardless of whether the field is empty or not. This may be
  133. // used to include empty fields in Patch requests.
  134. ForceSendFields []string `json:"-"`
  135. // NullFields is a list of field names (e.g. "Detections") to include in
  136. // API requests with the JSON null value. By default, fields with empty
  137. // values are omitted from API requests. However, any field with an
  138. // empty value appearing in NullFields will be sent to the server as
  139. // null. It is an error if a field in this list has a non-empty value.
  140. // This may be used to include null fields in Patch requests.
  141. NullFields []string `json:"-"`
  142. }
  143. func (s *DetectionsListResponse) MarshalJSON() ([]byte, error) {
  144. type NoMethod DetectionsListResponse
  145. raw := NoMethod(*s)
  146. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  147. }
  148. type DetectionsResourceItem struct {
  149. // Confidence: The confidence of the detection result of this language.
  150. Confidence float64 `json:"confidence,omitempty"`
  151. // IsReliable: A boolean to indicate is the language detection result
  152. // reliable.
  153. IsReliable bool `json:"isReliable,omitempty"`
  154. // Language: The language we detected.
  155. Language string `json:"language,omitempty"`
  156. // ForceSendFields is a list of field names (e.g. "Confidence") to
  157. // unconditionally include in API requests. By default, fields with
  158. // empty values are omitted from API requests. However, any non-pointer,
  159. // non-interface field appearing in ForceSendFields will be sent to the
  160. // server regardless of whether the field is empty or not. This may be
  161. // used to include empty fields in Patch requests.
  162. ForceSendFields []string `json:"-"`
  163. // NullFields is a list of field names (e.g. "Confidence") to include in
  164. // API requests with the JSON null value. By default, fields with empty
  165. // values are omitted from API requests. However, any field with an
  166. // empty value appearing in NullFields will be sent to the server as
  167. // null. It is an error if a field in this list has a non-empty value.
  168. // This may be used to include null fields in Patch requests.
  169. NullFields []string `json:"-"`
  170. }
  171. func (s *DetectionsResourceItem) MarshalJSON() ([]byte, error) {
  172. type NoMethod DetectionsResourceItem
  173. raw := NoMethod(*s)
  174. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  175. }
  176. func (s *DetectionsResourceItem) UnmarshalJSON(data []byte) error {
  177. type NoMethod DetectionsResourceItem
  178. var s1 struct {
  179. Confidence gensupport.JSONFloat64 `json:"confidence"`
  180. *NoMethod
  181. }
  182. s1.NoMethod = (*NoMethod)(s)
  183. if err := json.Unmarshal(data, &s1); err != nil {
  184. return err
  185. }
  186. s.Confidence = float64(s1.Confidence)
  187. return nil
  188. }
  189. // GetSupportedLanguagesRequest: The request message for discovering
  190. // supported languages.
  191. type GetSupportedLanguagesRequest struct {
  192. // Target: The language to use to return localized, human readable names
  193. // of supported
  194. // languages.
  195. Target string `json:"target,omitempty"`
  196. // ForceSendFields is a list of field names (e.g. "Target") to
  197. // unconditionally include in API requests. By default, fields with
  198. // empty values are omitted from API requests. However, any non-pointer,
  199. // non-interface field appearing in ForceSendFields will be sent to the
  200. // server regardless of whether the field is empty or not. This may be
  201. // used to include empty fields in Patch requests.
  202. ForceSendFields []string `json:"-"`
  203. // NullFields is a list of field names (e.g. "Target") to include in API
  204. // requests with the JSON null value. By default, fields with empty
  205. // values are omitted from API requests. However, any field with an
  206. // empty value appearing in NullFields will be sent to the server as
  207. // null. It is an error if a field in this list has a non-empty value.
  208. // This may be used to include null fields in Patch requests.
  209. NullFields []string `json:"-"`
  210. }
  211. func (s *GetSupportedLanguagesRequest) MarshalJSON() ([]byte, error) {
  212. type NoMethod GetSupportedLanguagesRequest
  213. raw := NoMethod(*s)
  214. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  215. }
  216. type LanguagesListResponse struct {
  217. // Languages: List of source/target languages supported by the
  218. // translation API. If target parameter is unspecified, the list is
  219. // sorted by the ASCII code point order of the language code. If target
  220. // parameter is specified, the list is sorted by the collation order of
  221. // the language name in the target language.
  222. Languages []*LanguagesResource `json:"languages,omitempty"`
  223. // ServerResponse contains the HTTP response code and headers from the
  224. // server.
  225. googleapi.ServerResponse `json:"-"`
  226. // ForceSendFields is a list of field names (e.g. "Languages") to
  227. // unconditionally include in API requests. By default, fields with
  228. // empty values are omitted from API requests. However, any non-pointer,
  229. // non-interface field appearing in ForceSendFields will be sent to the
  230. // server regardless of whether the field is empty or not. This may be
  231. // used to include empty fields in Patch requests.
  232. ForceSendFields []string `json:"-"`
  233. // NullFields is a list of field names (e.g. "Languages") to include in
  234. // API requests with the JSON null value. By default, fields with empty
  235. // values are omitted from API requests. However, any field with an
  236. // empty value appearing in NullFields will be sent to the server as
  237. // null. It is an error if a field in this list has a non-empty value.
  238. // This may be used to include null fields in Patch requests.
  239. NullFields []string `json:"-"`
  240. }
  241. func (s *LanguagesListResponse) MarshalJSON() ([]byte, error) {
  242. type NoMethod LanguagesListResponse
  243. raw := NoMethod(*s)
  244. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  245. }
  246. type LanguagesResource struct {
  247. // Language: Supported language code, generally consisting of its ISO
  248. // 639-1
  249. // identifier. (E.g. 'en', 'ja'). In certain cases, BCP-47 codes
  250. // including
  251. // language + region identifiers are returned (e.g. 'zh-TW' and 'zh-CH')
  252. Language string `json:"language,omitempty"`
  253. // Name: Human readable name of the language localized to the target
  254. // language.
  255. Name string `json:"name,omitempty"`
  256. // ForceSendFields is a list of field names (e.g. "Language") to
  257. // unconditionally include in API requests. By default, fields with
  258. // empty values are omitted from API requests. However, any non-pointer,
  259. // non-interface field appearing in ForceSendFields will be sent to the
  260. // server regardless of whether the field is empty or not. This may be
  261. // used to include empty fields in Patch requests.
  262. ForceSendFields []string `json:"-"`
  263. // NullFields is a list of field names (e.g. "Language") to include in
  264. // API requests with the JSON null value. By default, fields with empty
  265. // values are omitted from API requests. However, any field with an
  266. // empty value appearing in NullFields will be sent to the server as
  267. // null. It is an error if a field in this list has a non-empty value.
  268. // This may be used to include null fields in Patch requests.
  269. NullFields []string `json:"-"`
  270. }
  271. func (s *LanguagesResource) MarshalJSON() ([]byte, error) {
  272. type NoMethod LanguagesResource
  273. raw := NoMethod(*s)
  274. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  275. }
  276. // TranslateTextRequest: The main translation request message for the
  277. // Cloud Translation API.
  278. type TranslateTextRequest struct {
  279. // Format: The format of the source text, in either HTML (default) or
  280. // plain-text. A
  281. // value of "html" indicates HTML and a value of "text" indicates
  282. // plain-text.
  283. Format string `json:"format,omitempty"`
  284. // Model: The `model` type requested for this translation. Valid values
  285. // are
  286. // listed in public documentation.
  287. Model string `json:"model,omitempty"`
  288. // Q: The input text to translate. Repeat this parameter to perform
  289. // translation
  290. // operations on multiple text inputs.
  291. Q []string `json:"q,omitempty"`
  292. // Source: The language of the source text, set to one of the language
  293. // codes listed in
  294. // Language Support. If the source language is not specified, the API
  295. // will
  296. // attempt to identify the source language automatically and return it
  297. // within
  298. // the response.
  299. Source string `json:"source,omitempty"`
  300. // Target: The language to use for translation of the input text, set to
  301. // one of the
  302. // language codes listed in Language Support.
  303. Target string `json:"target,omitempty"`
  304. // ForceSendFields is a list of field names (e.g. "Format") to
  305. // unconditionally include in API requests. By default, fields with
  306. // empty values are omitted from API requests. However, any non-pointer,
  307. // non-interface field appearing in ForceSendFields will be sent to the
  308. // server regardless of whether the field is empty or not. This may be
  309. // used to include empty fields in Patch requests.
  310. ForceSendFields []string `json:"-"`
  311. // NullFields is a list of field names (e.g. "Format") to include in API
  312. // requests with the JSON null value. By default, fields with empty
  313. // values are omitted from API requests. However, any field with an
  314. // empty value appearing in NullFields will be sent to the server as
  315. // null. It is an error if a field in this list has a non-empty value.
  316. // This may be used to include null fields in Patch requests.
  317. NullFields []string `json:"-"`
  318. }
  319. func (s *TranslateTextRequest) MarshalJSON() ([]byte, error) {
  320. type NoMethod TranslateTextRequest
  321. raw := NoMethod(*s)
  322. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  323. }
  324. // TranslationsListResponse: The main language translation response
  325. // message.
  326. type TranslationsListResponse struct {
  327. // Translations: Translations contains list of translation results of
  328. // given text
  329. Translations []*TranslationsResource `json:"translations,omitempty"`
  330. // ServerResponse contains the HTTP response code and headers from the
  331. // server.
  332. googleapi.ServerResponse `json:"-"`
  333. // ForceSendFields is a list of field names (e.g. "Translations") to
  334. // unconditionally include in API requests. By default, fields with
  335. // empty values are omitted from API requests. However, any non-pointer,
  336. // non-interface field appearing in ForceSendFields will be sent to the
  337. // server regardless of whether the field is empty or not. This may be
  338. // used to include empty fields in Patch requests.
  339. ForceSendFields []string `json:"-"`
  340. // NullFields is a list of field names (e.g. "Translations") to include
  341. // in API requests with the JSON null value. By default, fields with
  342. // empty values are omitted from API requests. However, any field with
  343. // an empty value appearing in NullFields will be sent to the server as
  344. // null. It is an error if a field in this list has a non-empty value.
  345. // This may be used to include null fields in Patch requests.
  346. NullFields []string `json:"-"`
  347. }
  348. func (s *TranslationsListResponse) MarshalJSON() ([]byte, error) {
  349. type NoMethod TranslationsListResponse
  350. raw := NoMethod(*s)
  351. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  352. }
  353. type TranslationsResource struct {
  354. // DetectedSourceLanguage: The source language of the initial request,
  355. // detected automatically, if
  356. // no source language was passed within the initial request. If
  357. // the
  358. // source language was passed, auto-detection of the language will
  359. // not
  360. // occur and this field will be empty.
  361. DetectedSourceLanguage string `json:"detectedSourceLanguage,omitempty"`
  362. // Model: The `model` type used for this translation. Valid values
  363. // are
  364. // listed in public documentation. Can be different from requested
  365. // `model`.
  366. // Present only if specific model type was explicitly requested.
  367. Model string `json:"model,omitempty"`
  368. // TranslatedText: Text translated into the target language.
  369. TranslatedText string `json:"translatedText,omitempty"`
  370. // ForceSendFields is a list of field names (e.g.
  371. // "DetectedSourceLanguage") to unconditionally include in API requests.
  372. // By default, fields with empty values are omitted from API requests.
  373. // However, any non-pointer, non-interface field appearing in
  374. // ForceSendFields will be sent to the server regardless of whether the
  375. // field is empty or not. This may be used to include empty fields in
  376. // Patch requests.
  377. ForceSendFields []string `json:"-"`
  378. // NullFields is a list of field names (e.g. "DetectedSourceLanguage")
  379. // to include in API requests with the JSON null value. By default,
  380. // fields with empty values are omitted from API requests. However, any
  381. // field with an empty value appearing in NullFields will be sent to the
  382. // server as null. It is an error if a field in this list has a
  383. // non-empty value. This may be used to include null fields in Patch
  384. // requests.
  385. NullFields []string `json:"-"`
  386. }
  387. func (s *TranslationsResource) MarshalJSON() ([]byte, error) {
  388. type NoMethod TranslationsResource
  389. raw := NoMethod(*s)
  390. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  391. }
  392. // method id "language.detections.detect":
  393. type DetectionsDetectCall struct {
  394. s *Service
  395. detectlanguagerequest *DetectLanguageRequest
  396. urlParams_ gensupport.URLParams
  397. ctx_ context.Context
  398. header_ http.Header
  399. }
  400. // Detect: Detects the language of text within a request.
  401. func (r *DetectionsService) Detect(detectlanguagerequest *DetectLanguageRequest) *DetectionsDetectCall {
  402. c := &DetectionsDetectCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  403. c.detectlanguagerequest = detectlanguagerequest
  404. return c
  405. }
  406. // Fields allows partial responses to be retrieved. See
  407. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  408. // for more information.
  409. func (c *DetectionsDetectCall) Fields(s ...googleapi.Field) *DetectionsDetectCall {
  410. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  411. return c
  412. }
  413. // Context sets the context to be used in this call's Do method. Any
  414. // pending HTTP request will be aborted if the provided context is
  415. // canceled.
  416. func (c *DetectionsDetectCall) Context(ctx context.Context) *DetectionsDetectCall {
  417. c.ctx_ = ctx
  418. return c
  419. }
  420. // Header returns an http.Header that can be modified by the caller to
  421. // add HTTP headers to the request.
  422. func (c *DetectionsDetectCall) Header() http.Header {
  423. if c.header_ == nil {
  424. c.header_ = make(http.Header)
  425. }
  426. return c.header_
  427. }
  428. func (c *DetectionsDetectCall) doRequest(alt string) (*http.Response, error) {
  429. reqHeaders := make(http.Header)
  430. for k, v := range c.header_ {
  431. reqHeaders[k] = v
  432. }
  433. reqHeaders.Set("User-Agent", c.s.userAgent())
  434. var body io.Reader = nil
  435. body, err := googleapi.WithDataWrapper.JSONReader(c.detectlanguagerequest)
  436. if err != nil {
  437. return nil, err
  438. }
  439. reqHeaders.Set("Content-Type", "application/json")
  440. c.urlParams_.Set("alt", alt)
  441. urls := googleapi.ResolveRelative(c.s.BasePath, "v2/detect")
  442. urls += "?" + c.urlParams_.Encode()
  443. req, _ := http.NewRequest("POST", urls, body)
  444. req.Header = reqHeaders
  445. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  446. }
  447. // Do executes the "language.detections.detect" call.
  448. // Exactly one of *DetectionsListResponse or error will be non-nil. Any
  449. // non-2xx status code is an error. Response headers are in either
  450. // *DetectionsListResponse.ServerResponse.Header or (if a response was
  451. // returned at all) in error.(*googleapi.Error).Header. Use
  452. // googleapi.IsNotModified to check whether the returned error was
  453. // because http.StatusNotModified was returned.
  454. func (c *DetectionsDetectCall) Do(opts ...googleapi.CallOption) (*DetectionsListResponse, error) {
  455. gensupport.SetOptions(c.urlParams_, opts...)
  456. res, err := c.doRequest("json")
  457. if res != nil && res.StatusCode == http.StatusNotModified {
  458. if res.Body != nil {
  459. res.Body.Close()
  460. }
  461. return nil, &googleapi.Error{
  462. Code: res.StatusCode,
  463. Header: res.Header,
  464. }
  465. }
  466. if err != nil {
  467. return nil, err
  468. }
  469. defer googleapi.CloseBody(res)
  470. if err := googleapi.CheckResponse(res); err != nil {
  471. return nil, err
  472. }
  473. ret := &DetectionsListResponse{
  474. ServerResponse: googleapi.ServerResponse{
  475. Header: res.Header,
  476. HTTPStatusCode: res.StatusCode,
  477. },
  478. }
  479. target := &struct {
  480. Data *DetectionsListResponse `json:"data"`
  481. }{ret}
  482. if err := gensupport.DecodeResponse(target, res); err != nil {
  483. return nil, err
  484. }
  485. return ret, nil
  486. // {
  487. // "description": "Detects the language of text within a request.",
  488. // "httpMethod": "POST",
  489. // "id": "language.detections.detect",
  490. // "parameterOrder": [],
  491. // "parameters": {},
  492. // "path": "v2/detect",
  493. // "request": {
  494. // "$ref": "DetectLanguageRequest"
  495. // },
  496. // "response": {
  497. // "$ref": "DetectionsListResponse"
  498. // },
  499. // "scopes": [
  500. // "https://www.googleapis.com/auth/cloud-translation",
  501. // "https://www.googleapis.com/auth/cloud-platform"
  502. // ]
  503. // }
  504. }
  505. // method id "language.detections.list":
  506. type DetectionsListCall struct {
  507. s *Service
  508. urlParams_ gensupport.URLParams
  509. ifNoneMatch_ string
  510. ctx_ context.Context
  511. header_ http.Header
  512. }
  513. // List: Detects the language of text within a request.
  514. func (r *DetectionsService) List(q []string) *DetectionsListCall {
  515. c := &DetectionsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  516. c.urlParams_.SetMulti("q", append([]string{}, q...))
  517. return c
  518. }
  519. // Fields allows partial responses to be retrieved. See
  520. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  521. // for more information.
  522. func (c *DetectionsListCall) Fields(s ...googleapi.Field) *DetectionsListCall {
  523. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  524. return c
  525. }
  526. // IfNoneMatch sets the optional parameter which makes the operation
  527. // fail if the object's ETag matches the given value. This is useful for
  528. // getting updates only after the object has changed since the last
  529. // request. Use googleapi.IsNotModified to check whether the response
  530. // error from Do is the result of In-None-Match.
  531. func (c *DetectionsListCall) IfNoneMatch(entityTag string) *DetectionsListCall {
  532. c.ifNoneMatch_ = entityTag
  533. return c
  534. }
  535. // Context sets the context to be used in this call's Do method. Any
  536. // pending HTTP request will be aborted if the provided context is
  537. // canceled.
  538. func (c *DetectionsListCall) Context(ctx context.Context) *DetectionsListCall {
  539. c.ctx_ = ctx
  540. return c
  541. }
  542. // Header returns an http.Header that can be modified by the caller to
  543. // add HTTP headers to the request.
  544. func (c *DetectionsListCall) Header() http.Header {
  545. if c.header_ == nil {
  546. c.header_ = make(http.Header)
  547. }
  548. return c.header_
  549. }
  550. func (c *DetectionsListCall) doRequest(alt string) (*http.Response, error) {
  551. reqHeaders := make(http.Header)
  552. for k, v := range c.header_ {
  553. reqHeaders[k] = v
  554. }
  555. reqHeaders.Set("User-Agent", c.s.userAgent())
  556. if c.ifNoneMatch_ != "" {
  557. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  558. }
  559. var body io.Reader = nil
  560. c.urlParams_.Set("alt", alt)
  561. urls := googleapi.ResolveRelative(c.s.BasePath, "v2/detect")
  562. urls += "?" + c.urlParams_.Encode()
  563. req, _ := http.NewRequest("GET", urls, body)
  564. req.Header = reqHeaders
  565. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  566. }
  567. // Do executes the "language.detections.list" call.
  568. // Exactly one of *DetectionsListResponse or error will be non-nil. Any
  569. // non-2xx status code is an error. Response headers are in either
  570. // *DetectionsListResponse.ServerResponse.Header or (if a response was
  571. // returned at all) in error.(*googleapi.Error).Header. Use
  572. // googleapi.IsNotModified to check whether the returned error was
  573. // because http.StatusNotModified was returned.
  574. func (c *DetectionsListCall) Do(opts ...googleapi.CallOption) (*DetectionsListResponse, error) {
  575. gensupport.SetOptions(c.urlParams_, opts...)
  576. res, err := c.doRequest("json")
  577. if res != nil && res.StatusCode == http.StatusNotModified {
  578. if res.Body != nil {
  579. res.Body.Close()
  580. }
  581. return nil, &googleapi.Error{
  582. Code: res.StatusCode,
  583. Header: res.Header,
  584. }
  585. }
  586. if err != nil {
  587. return nil, err
  588. }
  589. defer googleapi.CloseBody(res)
  590. if err := googleapi.CheckResponse(res); err != nil {
  591. return nil, err
  592. }
  593. ret := &DetectionsListResponse{
  594. ServerResponse: googleapi.ServerResponse{
  595. Header: res.Header,
  596. HTTPStatusCode: res.StatusCode,
  597. },
  598. }
  599. target := &struct {
  600. Data *DetectionsListResponse `json:"data"`
  601. }{ret}
  602. if err := gensupport.DecodeResponse(target, res); err != nil {
  603. return nil, err
  604. }
  605. return ret, nil
  606. // {
  607. // "description": "Detects the language of text within a request.",
  608. // "httpMethod": "GET",
  609. // "id": "language.detections.list",
  610. // "parameterOrder": [
  611. // "q"
  612. // ],
  613. // "parameters": {
  614. // "q": {
  615. // "description": "The input text upon which to perform language detection. Repeat this\nparameter to perform language detection on multiple text inputs.",
  616. // "location": "query",
  617. // "repeated": true,
  618. // "required": true,
  619. // "type": "string"
  620. // }
  621. // },
  622. // "path": "v2/detect",
  623. // "response": {
  624. // "$ref": "DetectionsListResponse"
  625. // },
  626. // "scopes": [
  627. // "https://www.googleapis.com/auth/cloud-translation",
  628. // "https://www.googleapis.com/auth/cloud-platform"
  629. // ]
  630. // }
  631. }
  632. // method id "language.languages.list":
  633. type LanguagesListCall struct {
  634. s *Service
  635. urlParams_ gensupport.URLParams
  636. ifNoneMatch_ string
  637. ctx_ context.Context
  638. header_ http.Header
  639. }
  640. // List: Returns a list of supported languages for translation.
  641. func (r *LanguagesService) List() *LanguagesListCall {
  642. c := &LanguagesListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  643. return c
  644. }
  645. // Model sets the optional parameter "model": The model type for which
  646. // supported languages should be returned.
  647. func (c *LanguagesListCall) Model(model string) *LanguagesListCall {
  648. c.urlParams_.Set("model", model)
  649. return c
  650. }
  651. // Target sets the optional parameter "target": The language to use to
  652. // return localized, human readable names of supported
  653. // languages.
  654. func (c *LanguagesListCall) Target(target string) *LanguagesListCall {
  655. c.urlParams_.Set("target", target)
  656. return c
  657. }
  658. // Fields allows partial responses to be retrieved. See
  659. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  660. // for more information.
  661. func (c *LanguagesListCall) Fields(s ...googleapi.Field) *LanguagesListCall {
  662. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  663. return c
  664. }
  665. // IfNoneMatch sets the optional parameter which makes the operation
  666. // fail if the object's ETag matches the given value. This is useful for
  667. // getting updates only after the object has changed since the last
  668. // request. Use googleapi.IsNotModified to check whether the response
  669. // error from Do is the result of In-None-Match.
  670. func (c *LanguagesListCall) IfNoneMatch(entityTag string) *LanguagesListCall {
  671. c.ifNoneMatch_ = entityTag
  672. return c
  673. }
  674. // Context sets the context to be used in this call's Do method. Any
  675. // pending HTTP request will be aborted if the provided context is
  676. // canceled.
  677. func (c *LanguagesListCall) Context(ctx context.Context) *LanguagesListCall {
  678. c.ctx_ = ctx
  679. return c
  680. }
  681. // Header returns an http.Header that can be modified by the caller to
  682. // add HTTP headers to the request.
  683. func (c *LanguagesListCall) Header() http.Header {
  684. if c.header_ == nil {
  685. c.header_ = make(http.Header)
  686. }
  687. return c.header_
  688. }
  689. func (c *LanguagesListCall) doRequest(alt string) (*http.Response, error) {
  690. reqHeaders := make(http.Header)
  691. for k, v := range c.header_ {
  692. reqHeaders[k] = v
  693. }
  694. reqHeaders.Set("User-Agent", c.s.userAgent())
  695. if c.ifNoneMatch_ != "" {
  696. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  697. }
  698. var body io.Reader = nil
  699. c.urlParams_.Set("alt", alt)
  700. urls := googleapi.ResolveRelative(c.s.BasePath, "v2/languages")
  701. urls += "?" + c.urlParams_.Encode()
  702. req, _ := http.NewRequest("GET", urls, body)
  703. req.Header = reqHeaders
  704. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  705. }
  706. // Do executes the "language.languages.list" call.
  707. // Exactly one of *LanguagesListResponse or error will be non-nil. Any
  708. // non-2xx status code is an error. Response headers are in either
  709. // *LanguagesListResponse.ServerResponse.Header or (if a response was
  710. // returned at all) in error.(*googleapi.Error).Header. Use
  711. // googleapi.IsNotModified to check whether the returned error was
  712. // because http.StatusNotModified was returned.
  713. func (c *LanguagesListCall) Do(opts ...googleapi.CallOption) (*LanguagesListResponse, error) {
  714. gensupport.SetOptions(c.urlParams_, opts...)
  715. res, err := c.doRequest("json")
  716. if res != nil && res.StatusCode == http.StatusNotModified {
  717. if res.Body != nil {
  718. res.Body.Close()
  719. }
  720. return nil, &googleapi.Error{
  721. Code: res.StatusCode,
  722. Header: res.Header,
  723. }
  724. }
  725. if err != nil {
  726. return nil, err
  727. }
  728. defer googleapi.CloseBody(res)
  729. if err := googleapi.CheckResponse(res); err != nil {
  730. return nil, err
  731. }
  732. ret := &LanguagesListResponse{
  733. ServerResponse: googleapi.ServerResponse{
  734. Header: res.Header,
  735. HTTPStatusCode: res.StatusCode,
  736. },
  737. }
  738. target := &struct {
  739. Data *LanguagesListResponse `json:"data"`
  740. }{ret}
  741. if err := gensupport.DecodeResponse(target, res); err != nil {
  742. return nil, err
  743. }
  744. return ret, nil
  745. // {
  746. // "description": "Returns a list of supported languages for translation.",
  747. // "httpMethod": "GET",
  748. // "id": "language.languages.list",
  749. // "parameters": {
  750. // "model": {
  751. // "description": "The model type for which supported languages should be returned.",
  752. // "location": "query",
  753. // "type": "string"
  754. // },
  755. // "target": {
  756. // "description": "The language to use to return localized, human readable names of supported\nlanguages.",
  757. // "location": "query",
  758. // "type": "string"
  759. // }
  760. // },
  761. // "path": "v2/languages",
  762. // "response": {
  763. // "$ref": "LanguagesListResponse"
  764. // },
  765. // "scopes": [
  766. // "https://www.googleapis.com/auth/cloud-translation",
  767. // "https://www.googleapis.com/auth/cloud-platform"
  768. // ]
  769. // }
  770. }
  771. // method id "language.translations.list":
  772. type TranslationsListCall struct {
  773. s *Service
  774. urlParams_ gensupport.URLParams
  775. ifNoneMatch_ string
  776. ctx_ context.Context
  777. header_ http.Header
  778. }
  779. // List: Translates input text, returning translated text.
  780. func (r *TranslationsService) List(q []string, target string) *TranslationsListCall {
  781. c := &TranslationsListCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  782. c.urlParams_.SetMulti("q", append([]string{}, q...))
  783. c.urlParams_.Set("target", target)
  784. return c
  785. }
  786. // Cid sets the optional parameter "cid": The customization id for
  787. // translate
  788. func (c *TranslationsListCall) Cid(cid ...string) *TranslationsListCall {
  789. c.urlParams_.SetMulti("cid", append([]string{}, cid...))
  790. return c
  791. }
  792. // Format sets the optional parameter "format": The format of the source
  793. // text, in either HTML (default) or plain-text. A
  794. // value of "html" indicates HTML and a value of "text" indicates
  795. // plain-text.
  796. //
  797. // Possible values:
  798. // "html" - Specifies the input is in HTML
  799. // "text" - Specifies the input is in plain textual format
  800. func (c *TranslationsListCall) Format(format string) *TranslationsListCall {
  801. c.urlParams_.Set("format", format)
  802. return c
  803. }
  804. // Model sets the optional parameter "model": The `model` type requested
  805. // for this translation. Valid values are
  806. // listed in public documentation.
  807. func (c *TranslationsListCall) Model(model string) *TranslationsListCall {
  808. c.urlParams_.Set("model", model)
  809. return c
  810. }
  811. // Source sets the optional parameter "source": The language of the
  812. // source text, set to one of the language codes listed in
  813. // Language Support. If the source language is not specified, the API
  814. // will
  815. // attempt to identify the source language automatically and return it
  816. // within
  817. // the response.
  818. func (c *TranslationsListCall) Source(source string) *TranslationsListCall {
  819. c.urlParams_.Set("source", source)
  820. return c
  821. }
  822. // Fields allows partial responses to be retrieved. See
  823. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  824. // for more information.
  825. func (c *TranslationsListCall) Fields(s ...googleapi.Field) *TranslationsListCall {
  826. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  827. return c
  828. }
  829. // IfNoneMatch sets the optional parameter which makes the operation
  830. // fail if the object's ETag matches the given value. This is useful for
  831. // getting updates only after the object has changed since the last
  832. // request. Use googleapi.IsNotModified to check whether the response
  833. // error from Do is the result of In-None-Match.
  834. func (c *TranslationsListCall) IfNoneMatch(entityTag string) *TranslationsListCall {
  835. c.ifNoneMatch_ = entityTag
  836. return c
  837. }
  838. // Context sets the context to be used in this call's Do method. Any
  839. // pending HTTP request will be aborted if the provided context is
  840. // canceled.
  841. func (c *TranslationsListCall) Context(ctx context.Context) *TranslationsListCall {
  842. c.ctx_ = ctx
  843. return c
  844. }
  845. // Header returns an http.Header that can be modified by the caller to
  846. // add HTTP headers to the request.
  847. func (c *TranslationsListCall) Header() http.Header {
  848. if c.header_ == nil {
  849. c.header_ = make(http.Header)
  850. }
  851. return c.header_
  852. }
  853. func (c *TranslationsListCall) doRequest(alt string) (*http.Response, error) {
  854. reqHeaders := make(http.Header)
  855. for k, v := range c.header_ {
  856. reqHeaders[k] = v
  857. }
  858. reqHeaders.Set("User-Agent", c.s.userAgent())
  859. if c.ifNoneMatch_ != "" {
  860. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  861. }
  862. var body io.Reader = nil
  863. c.urlParams_.Set("alt", alt)
  864. urls := googleapi.ResolveRelative(c.s.BasePath, "v2")
  865. urls += "?" + c.urlParams_.Encode()
  866. req, _ := http.NewRequest("GET", urls, body)
  867. req.Header = reqHeaders
  868. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  869. }
  870. // Do executes the "language.translations.list" call.
  871. // Exactly one of *TranslationsListResponse or error will be non-nil.
  872. // Any non-2xx status code is an error. Response headers are in either
  873. // *TranslationsListResponse.ServerResponse.Header or (if a response was
  874. // returned at all) in error.(*googleapi.Error).Header. Use
  875. // googleapi.IsNotModified to check whether the returned error was
  876. // because http.StatusNotModified was returned.
  877. func (c *TranslationsListCall) Do(opts ...googleapi.CallOption) (*TranslationsListResponse, error) {
  878. gensupport.SetOptions(c.urlParams_, opts...)
  879. res, err := c.doRequest("json")
  880. if res != nil && res.StatusCode == http.StatusNotModified {
  881. if res.Body != nil {
  882. res.Body.Close()
  883. }
  884. return nil, &googleapi.Error{
  885. Code: res.StatusCode,
  886. Header: res.Header,
  887. }
  888. }
  889. if err != nil {
  890. return nil, err
  891. }
  892. defer googleapi.CloseBody(res)
  893. if err := googleapi.CheckResponse(res); err != nil {
  894. return nil, err
  895. }
  896. ret := &TranslationsListResponse{
  897. ServerResponse: googleapi.ServerResponse{
  898. Header: res.Header,
  899. HTTPStatusCode: res.StatusCode,
  900. },
  901. }
  902. target := &struct {
  903. Data *TranslationsListResponse `json:"data"`
  904. }{ret}
  905. if err := gensupport.DecodeResponse(target, res); err != nil {
  906. return nil, err
  907. }
  908. return ret, nil
  909. // {
  910. // "description": "Translates input text, returning translated text.",
  911. // "httpMethod": "GET",
  912. // "id": "language.translations.list",
  913. // "parameterOrder": [
  914. // "q",
  915. // "target"
  916. // ],
  917. // "parameters": {
  918. // "cid": {
  919. // "description": "The customization id for translate",
  920. // "location": "query",
  921. // "repeated": true,
  922. // "type": "string"
  923. // },
  924. // "format": {
  925. // "description": "The format of the source text, in either HTML (default) or plain-text. A\nvalue of \"html\" indicates HTML and a value of \"text\" indicates plain-text.",
  926. // "enum": [
  927. // "html",
  928. // "text"
  929. // ],
  930. // "enumDescriptions": [
  931. // "Specifies the input is in HTML",
  932. // "Specifies the input is in plain textual format"
  933. // ],
  934. // "location": "query",
  935. // "type": "string"
  936. // },
  937. // "model": {
  938. // "description": "The `model` type requested for this translation. Valid values are\nlisted in public documentation.",
  939. // "location": "query",
  940. // "type": "string"
  941. // },
  942. // "q": {
  943. // "description": "The input text to translate. Repeat this parameter to perform translation\noperations on multiple text inputs.",
  944. // "location": "query",
  945. // "repeated": true,
  946. // "required": true,
  947. // "type": "string"
  948. // },
  949. // "source": {
  950. // "description": "The language of the source text, set to one of the language codes listed in\nLanguage Support. If the source language is not specified, the API will\nattempt to identify the source language automatically and return it within\nthe response.",
  951. // "location": "query",
  952. // "type": "string"
  953. // },
  954. // "target": {
  955. // "description": "The language to use for translation of the input text, set to one of the\nlanguage codes listed in Language Support.",
  956. // "location": "query",
  957. // "required": true,
  958. // "type": "string"
  959. // }
  960. // },
  961. // "path": "v2",
  962. // "response": {
  963. // "$ref": "TranslationsListResponse"
  964. // },
  965. // "scopes": [
  966. // "https://www.googleapis.com/auth/cloud-translation",
  967. // "https://www.googleapis.com/auth/cloud-platform"
  968. // ]
  969. // }
  970. }
  971. // method id "language.translations.translate":
  972. type TranslationsTranslateCall struct {
  973. s *Service
  974. translatetextrequest *TranslateTextRequest
  975. urlParams_ gensupport.URLParams
  976. ctx_ context.Context
  977. header_ http.Header
  978. }
  979. // Translate: Translates input text, returning translated text.
  980. func (r *TranslationsService) Translate(translatetextrequest *TranslateTextRequest) *TranslationsTranslateCall {
  981. c := &TranslationsTranslateCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  982. c.translatetextrequest = translatetextrequest
  983. return c
  984. }
  985. // Fields allows partial responses to be retrieved. See
  986. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  987. // for more information.
  988. func (c *TranslationsTranslateCall) Fields(s ...googleapi.Field) *TranslationsTranslateCall {
  989. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  990. return c
  991. }
  992. // Context sets the context to be used in this call's Do method. Any
  993. // pending HTTP request will be aborted if the provided context is
  994. // canceled.
  995. func (c *TranslationsTranslateCall) Context(ctx context.Context) *TranslationsTranslateCall {
  996. c.ctx_ = ctx
  997. return c
  998. }
  999. // Header returns an http.Header that can be modified by the caller to
  1000. // add HTTP headers to the request.
  1001. func (c *TranslationsTranslateCall) Header() http.Header {
  1002. if c.header_ == nil {
  1003. c.header_ = make(http.Header)
  1004. }
  1005. return c.header_
  1006. }
  1007. func (c *TranslationsTranslateCall) doRequest(alt string) (*http.Response, error) {
  1008. reqHeaders := make(http.Header)
  1009. for k, v := range c.header_ {
  1010. reqHeaders[k] = v
  1011. }
  1012. reqHeaders.Set("User-Agent", c.s.userAgent())
  1013. var body io.Reader = nil
  1014. body, err := googleapi.WithDataWrapper.JSONReader(c.translatetextrequest)
  1015. if err != nil {
  1016. return nil, err
  1017. }
  1018. reqHeaders.Set("Content-Type", "application/json")
  1019. c.urlParams_.Set("alt", alt)
  1020. urls := googleapi.ResolveRelative(c.s.BasePath, "v2")
  1021. urls += "?" + c.urlParams_.Encode()
  1022. req, _ := http.NewRequest("POST", urls, body)
  1023. req.Header = reqHeaders
  1024. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  1025. }
  1026. // Do executes the "language.translations.translate" call.
  1027. // Exactly one of *TranslationsListResponse or error will be non-nil.
  1028. // Any non-2xx status code is an error. Response headers are in either
  1029. // *TranslationsListResponse.ServerResponse.Header or (if a response was
  1030. // returned at all) in error.(*googleapi.Error).Header. Use
  1031. // googleapi.IsNotModified to check whether the returned error was
  1032. // because http.StatusNotModified was returned.
  1033. func (c *TranslationsTranslateCall) Do(opts ...googleapi.CallOption) (*TranslationsListResponse, error) {
  1034. gensupport.SetOptions(c.urlParams_, opts...)
  1035. res, err := c.doRequest("json")
  1036. if res != nil && res.StatusCode == http.StatusNotModified {
  1037. if res.Body != nil {
  1038. res.Body.Close()
  1039. }
  1040. return nil, &googleapi.Error{
  1041. Code: res.StatusCode,
  1042. Header: res.Header,
  1043. }
  1044. }
  1045. if err != nil {
  1046. return nil, err
  1047. }
  1048. defer googleapi.CloseBody(res)
  1049. if err := googleapi.CheckResponse(res); err != nil {
  1050. return nil, err
  1051. }
  1052. ret := &TranslationsListResponse{
  1053. ServerResponse: googleapi.ServerResponse{
  1054. Header: res.Header,
  1055. HTTPStatusCode: res.StatusCode,
  1056. },
  1057. }
  1058. target := &struct {
  1059. Data *TranslationsListResponse `json:"data"`
  1060. }{ret}
  1061. if err := gensupport.DecodeResponse(target, res); err != nil {
  1062. return nil, err
  1063. }
  1064. return ret, nil
  1065. // {
  1066. // "description": "Translates input text, returning translated text.",
  1067. // "httpMethod": "POST",
  1068. // "id": "language.translations.translate",
  1069. // "parameterOrder": [],
  1070. // "parameters": {},
  1071. // "path": "v2",
  1072. // "request": {
  1073. // "$ref": "TranslateTextRequest"
  1074. // },
  1075. // "response": {
  1076. // "$ref": "TranslationsListResponse"
  1077. // },
  1078. // "scopes": [
  1079. // "https://www.googleapis.com/auth/cloud-translation",
  1080. // "https://www.googleapis.com/auth/cloud-platform"
  1081. // ]
  1082. // }
  1083. }