1
- Using the Translate Client
1
+ Translation v2 Usage Guide
2
2
--------------------------
3
3
4
4
To create a client:
5
5
6
6
.. doctest ::
7
7
8
- >>> from google.cloud import translate
9
- >>> client = translate .Client()
8
+ >>> from google.cloud import translate_v2
9
+ >>> client = translate_v2 .Client()
10
10
11
11
By default, the client targets English when doing detections
12
12
and translations, but a non-default value can be used as
13
13
well:
14
14
15
15
.. doctest ::
16
16
17
- >>> from google.cloud import translate
18
- >>> client = translate .Client(target_language = ' es' )
17
+ >>> from google.cloud import translate_v2
18
+ >>> client = translate_v2 .Client(target_language = ' es' )
19
19
20
- The Google Cloud Translation API has three supported methods, and they
20
+ The Google Cloud Translation v2 API has three supported methods, and they
21
21
map to three methods on a client:
22
- :meth: `~google.cloud.translate .client.Client.get_languages `,
23
- :meth: `~google.cloud.translate .client.Client.detect_language ` and
24
- :meth: `~google.cloud.translate .client.Client.translate `.
22
+ :meth: `~google.cloud.translate_v2 .client.Client.get_languages `,
23
+ :meth: `~google.cloud.translate_v2 .client.Client.detect_language ` and
24
+ :meth: `~google.cloud.translate_v2 .client.Client.translate `.
25
25
26
26
To get a list of languages supported by the Google Cloud Translation API
27
27
28
28
.. doctest ::
29
29
30
- >>> from google.cloud import translate
31
- >>> client = translate .Client()
30
+ >>> from google.cloud import translate_v2
31
+ >>> client = translate_v2 .Client()
32
32
>>> client.get_languages()
33
33
[
34
34
{
@@ -42,8 +42,8 @@ To detect the language that some given text is written in:
42
42
43
43
.. doctest ::
44
44
45
- >>> from google.cloud import translate
46
- >>> client = translate .Client()
45
+ >>> from google.cloud import translate_v2
46
+ >>> client = translate_v2 .Client()
47
47
>>> client.detect_language([' Me llamo' , ' I am' ])
48
48
[
49
49
{
@@ -68,8 +68,8 @@ the source language:
68
68
69
69
.. doctest ::
70
70
71
- >>> from google.cloud import translate
72
- >>> client = translate .Client()
71
+ >>> from google.cloud import translate_v2
72
+ >>> client = translate_v2 .Client()
73
73
>>> client.translate(' koszula' )
74
74
{
75
75
'translatedText': 'shirt',
@@ -81,8 +81,8 @@ If the source language is known:
81
81
82
82
.. doctest ::
83
83
84
- >>> from google.cloud import translate
85
- >>> client = translate .Client()
84
+ >>> from google.cloud import translate_v2
85
+ >>> client = translate_v2 .Client()
86
86
>>> client.translate(' camisa' , source_language = ' es' )
87
87
{
88
88
'translatedText': 'shirt',
@@ -93,8 +93,8 @@ or to use a non-default target language:
93
93
94
94
.. doctest ::
95
95
96
- >>> from google.cloud import translate
97
- >>> client = translate .Client()
96
+ >>> from google.cloud import translate_v2
97
+ >>> client = translate_v2 .Client()
98
98
>>> client.translate([' Me llamo Jeff' , ' My name is Jeff' ],
99
99
... target_language= ' de' )
100
100
[
0 commit comments