vendor: update all dependencies

This commit is contained in:
Nick Craig-Wood
2017-07-23 08:51:42 +01:00
parent 0b6fba34a3
commit eb87cf6f12
2008 changed files with 352617 additions and 1004734 deletions
+81
View File
@@ -0,0 +1,81 @@
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package translate_test
import (
"fmt"
"cloud.google.com/go/translate"
"golang.org/x/net/context"
"golang.org/x/text/language"
)
func Example_NewClient() {
ctx := context.Background()
client, err := translate.NewClient(ctx)
if err != nil {
// TODO: handle error.
}
// Use the client.
// Close the client when finished.
if err := client.Close(); err != nil {
// TODO: handle error.
}
}
func Example_Translate() {
ctx := context.Background()
client, err := translate.NewClient(ctx)
if err != nil {
// TODO: handle error.
}
translations, err := client.Translate(ctx,
[]string{"Le singe est sur la branche"}, language.English,
&translate.Options{
Source: language.French,
Format: translate.Text,
})
if err != nil {
// TODO: handle error.
}
fmt.Println(translations[0].Text)
}
func Example_DetectLanguage() {
ctx := context.Background()
client, err := translate.NewClient(ctx)
if err != nil {
// TODO: handle error.
}
ds, err := client.DetectLanguage(ctx, []string{"Today is Monday"})
if err != nil {
// TODO: handle error.
}
fmt.Println(ds)
}
func Example_SupportedLanguages() {
ctx := context.Background()
client, err := translate.NewClient(ctx)
if err != nil {
// TODO: handle error.
}
langs, err := client.SupportedLanguages(ctx, language.English)
if err != nil {
// TODO: handle error.
}
fmt.Println(langs)
}
+13 -6
View File
@@ -12,18 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Package translate is a client for the Google Translate API.
// See https://cloud.google.com/translate for details.
//
// This package is experimental and subject to change without notice.
// Package translate is a client for the Google Translation API.
// See https://cloud.google.com/translation for details.
package translate
import (
"fmt"
"net/http"
"google.golang.org/api/option"
"google.golang.org/api/transport"
"cloud.google.com/go/internal/version"
raw "cloud.google.com/go/translate/internal/translate/v2"
"golang.org/x/net/context"
"golang.org/x/text/language"
@@ -41,7 +41,7 @@ type Client struct {
const prodAddr = "https://translation.googleapis.com/language/translate/"
// NewClient constructs a new Client that can perform Translate operations.
// NewClient constructs a new Client that can perform Translation operations.
//
// You can find or create API key for your project from the Credentials page of
// the Developers Console (console.developers.google.com).
@@ -74,12 +74,13 @@ func (c *Client) Close() error { return nil }
//
// The target parameter supplies the language to translate to. The supported
// languages are listed at
// https://cloud.google.com/translate/v2/translate-reference#supported_languages.
// https://cloud.google.com/translation/v2/translate-reference#supported_languages.
// You can also call the SupportedLanguages method.
//
// The returned Translations appear in the same order as the inputs.
func (c *Client) Translate(ctx context.Context, inputs []string, target language.Tag, opts *Options) ([]Translation, error) {
call := c.raw.Translations.List(inputs, target.String()).Context(ctx)
setClientHeader(call.Header())
if opts != nil {
if s := opts.Source; s != language.Und {
call.Source(s.String())
@@ -161,6 +162,7 @@ type Translation struct {
// a single input string.
func (c *Client) DetectLanguage(ctx context.Context, inputs []string) ([][]Detection, error) {
call := c.raw.Detections.List(inputs).Context(ctx)
setClientHeader(call.Header())
res, err := call.Do()
if err != nil {
return nil, err
@@ -202,6 +204,7 @@ type Detection struct {
// readable names of supported languages.
func (c *Client) SupportedLanguages(ctx context.Context, target language.Tag) ([]Language, error) {
call := c.raw.Languages.List().Context(ctx).Target(target.String())
setClientHeader(call.Header())
res, err := call.Do()
if err != nil {
return nil, err
@@ -228,3 +231,7 @@ type Language struct {
// Tag is a standard code for the language.
Tag language.Tag
}
func setClientHeader(headers http.Header) {
headers.Set("x-goog-api-client", fmt.Sprintf("gl-go/%s gccl/%s", version.Go(), version.Repo))
}
+2 -3
View File
@@ -159,9 +159,8 @@ func TestTranslateOneInput(t *testing.T) {
// https://www.youtube.com/watch?v=x1sQkEfAdfY
{"Le singe est sur la branche", language.French,
"The monkey is on the branch", language.English},
// https://www.youtube.com/watch?v=akbflkF_1zY
{"I will not buy this record, it is scratched", language.English,
"Nem fogok vásárolni ezt a lemezt, azt karcos", language.Hungarian},
{"The cat is on the chair", language.English,
"Le chat est sur la chaise", language.French},
} {
// Provide source and format.
tr := translate(test.input, test.target, &Options{Source: test.source, Format: Text})