You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This sample will use the [Text Translation - Translate method](../cognitive-services/translator/reference/v3-0-translate.md) to translate a string of text from a language into another specified language. There are multiple [language codes](https://api.cognitive.microsofttranslator.com/languages?api-version=3.0&scope=translation,dictionary,transliteration) that can be used with the Text Translation API.
626
+
-`https://api.cognitive.microsofttranslator.us`
627
+
* There are 2 regions `USGovVirginia` and `USGovArizona`
628
+
### Text Translation Method
629
+
The below example uses [Text Translation - Translate method](../cognitive-services/translator/reference/v3-0-translate.md) to translate a string of text from a language into another specified language. There are multiple [language codes](https://api.cognitive.microsofttranslator.com/languages?api-version=3.0&scope=translation) that can be used with the Text Translation API.
629
630
630
631
### Text Translation C# example request
631
632
@@ -634,8 +635,9 @@ The sample is written in C#.
634
635
1. Create a new Console solution in Visual Studio.
635
636
2. Replace Program.cs with the corresponding code below.
636
637
3. Replace the `subscriptionKey` value with the key value that you retrieved above.
637
-
4. Replace the `text` value with text that you want to translate.
638
-
5. Run the program.
638
+
4. Replace the `region` value with the region value where you created your translator resource.
639
+
5. Replace the `text` value with text that you want to translate.
640
+
6. Run the program.
639
641
640
642
You can also test out different languages and texts by replacing the "text", "from", and "to" variables in Program.cs.
Copy file name to clipboardExpand all lines: articles/cognitive-services/Translator/reference/v3-0-reference.md
+79-15Lines changed: 79 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ manager: nitinme
8
8
ms.service: cognitive-services
9
9
ms.subservice: translator-text
10
10
ms.topic: reference
11
-
ms.date: 11/14/2019
11
+
ms.date: 3/13/2020
12
12
ms.author: swmachan
13
13
---
14
14
@@ -53,17 +53,74 @@ There are three headers that you can use to authenticate your subscription. This
53
53
|:----|:----|
54
54
|Ocp-Apim-Subscription-Key|*Use with Cognitive Services subscription if you are passing your secret key*.<br/>The value is the Azure secret key for your subscription to Translator Text API.|
55
55
|Authorization|*Use with Cognitive Services subscription if you are passing an authentication token.*<br/>The value is the Bearer token: `Bearer <token>`.|
56
-
|Ocp-Apim-Subscription-Region|*Use with Cognitive Services multi-service subscription if you are passing a multi-service secret key.*<br/>The value is the region of the multi-service subscription. This value is optional when not using a multi-service subscription.|
56
+
|Ocp-Apim-Subscription-Region|*Use with Cognitive Services multi-service and regional translator resource.*<br/>The value is the region of the multi-service or regional translator resource. This value is optional when using a global translator resource.|
57
57
58
58
### Secret key
59
59
The first option is to authenticate using the `Ocp-Apim-Subscription-Key` header. Add the `Ocp-Apim-Subscription-Key: <YOUR_SECRET_KEY>` header to your request.
60
60
61
-
### Authorization token
61
+
#### Authenticating with a global resource
62
+
63
+
When you use a [global translator resource](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesTextTranslation), you need to include one header to call the translator API.
64
+
65
+
|Headers|Description|
66
+
|:-----|:----|
67
+
|Ocp-Apim-Subscription-Key| The value is the Azure secret key for your subscription to Translator Text API.|
68
+
69
+
Here's an example request to call the Translator API using the global translator resource
70
+
71
+
```curl
72
+
// Pass secret key using headers
73
+
curl -X POST "https://api.cognitive.microsoft.com/translate?api-version=3.0&to=es" \
74
+
-H "Ocp-Apim-Subscription-Key:<your-key>" \
75
+
-H "Content-Type: application/json" \
76
+
-d "[{'Text':'Hello, what is your name?'}]"
77
+
```
78
+
79
+
#### Authenticating with a regional resource
80
+
81
+
When you use a [regional translator resource](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesTextTranslation).
82
+
There are 2 headers that you need to call the translator API.
83
+
84
+
|Headers|Description|
85
+
|:-----|:----|
86
+
|Ocp-Apim-Subscription-Key| The value is the Azure secret key for your subscription to Translator Text API.|
87
+
|Ocp-Apim-Subscription-Region| The value is the region of the translator resource. |
88
+
89
+
Here's an example request to call the Translator API using the regional translator resource
90
+
91
+
```curl
92
+
// Pass secret key and region using headers
93
+
curl -X POST "https://api.cognitive.microsoft.com/translate?api-version=3.0&to=es" \
94
+
-H "Ocp-Apim-Subscription-Key:<your-key>" \
95
+
-H "Ocp-Apim-Subscription-Region:<your-region>" \
96
+
-H "Content-Type: application/json" \
97
+
-d "[{'Text':'Hello, what is your name?'}]"
98
+
```
99
+
100
+
#### Authenticating with a Multi-service resource
101
+
102
+
When you use a Cognitive Service’s multi-service resource. This allows you to use a single secret key to authenticate requests for multiple services.
103
+
104
+
When you use a multi-service secret key, you must include two authentication headers with your request. There are 2 headers that you need to call the translator API.
105
+
106
+
|Headers|Description|
107
+
|:-----|:----|
108
+
|Ocp-Apim-Subscription-Key| The value is the Azure secret key for your multi-service resource.|
109
+
|Ocp-Apim-Subscription-Region| The value is the region of the multi-service resource. |
110
+
111
+
Region is required for the multi-service Text API subscription. The region you select is the only region that you can use for text translation when using the multi-service subscription key, and must be the same region you selected when you signed up for your multi-service subscription through the Azure portal.
112
+
113
+
Available regions are `australiaeast`, `brazilsouth`, `canadacentral`, `centralindia`, `centralus`, `centraluseuap`, `eastasia`, `eastus`, `eastus2`, `francecentral`, `japaneast`, `japanwest`, `koreacentral`, `northcentralus`, `northeurope`, `southcentralus`, `southeastasia`, `uksouth`, `westcentralus`, `westeurope`, `westus`, `westus2`, and `southafricanorth`.
114
+
115
+
If you pass the secret key in the query string with the parameter `Subscription-Key`, then you must specify the region with query parameter `Subscription-Region`.
116
+
117
+
### Authenticating with an access token
62
118
Alternatively, you can exchange your secret key for an access token. This token is included with each request as the `Authorization` header. To obtain an authorization token, make a `POST` request to the following URL:
An authentication token is valid for 10 minutes. The token should be reused when making multiple calls to the Translator APIs. However, if your program makes requests to the Translator API over an extended period of time, then your program must request a new access token at regular intervals (for example, every 8 minutes).
85
142
86
-
### Multi-service subscription
87
-
88
-
The last authentication option is to use a Cognitive Service’s multi-service subscription. This allows you to use a single secret key to authenticate requests for multiple services.
143
+
## Virtual Network support
89
144
90
-
When you use a multi-service secret key, you must include two authentication headers with your request. The first passes the secret key, the second specifies the region associated with your subscription.
91
-
*`Ocp-Apim-Subscription-Key`
92
-
*`Ocp-Apim-Subscription-Region`
145
+
Translator service is now available with Virtual Network capabilities in limited regions (`WestUS2`, `EastUS`, `SouthCentralUS`, `WestUS`, `Central US EUAP`, `global`). To enable Virtual Network, please see [Configuring Azure Cognitive Services Virtual Networks](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-virtual-networks?tabs=portal).
93
146
94
-
Region is required for the multi-service Text API subscription. The region you select is the only region that you can use for text translation when using the multi-service subscription key, and must be the same region you selected when you signed up for your multi-service subscription through the Azure portal.
147
+
Once you turn on this capability, you must use the custom endpoint to call the Translator API. You cannot use the global translator endpoint ("api.cognitive.microsofttranslator.com") and you cannot authenticate with an access token.
95
148
96
-
Available regions are `australiaeast`, `brazilsouth`, `canadacentral`, `centralindia`, `centralus`, `centraluseuap`, `eastasia`, `eastus`, `eastus2`, `francecentral`, `japaneast`, `japanwest`, `koreacentral`, `northcentralus`, `northeurope`, `southcentralus`, `southeastasia`, `uksouth`, `westcentralus`, `westeurope`, `westus`, `westus2`, and `southafricanorth`.
149
+
You can find the custom endpoint once you create the [translator resource](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesTextTranslation).
97
150
98
-
If you pass the secret key in the query string with the parameter `Subscription-Key`, then you must specify the region with query parameter `Subscription-Region`.
151
+
|Headers|Description|
152
+
|:-----|:----|
153
+
|Ocp-Apim-Subscription-Key| The value is the Azure secret key for your subscription to Translator Text API.|
154
+
|Ocp-Apim-Subscription-Region| The value is the region of the translator resource. This value is optional if the resource is `global`|
99
155
100
-
If you use a bearer token, you must obtain the token from the region endpoint: `https://<your-region>.api.cognitive.microsoft.com/sts/v1.0/issueToken`.
156
+
Here's an example request to call the Translator API using the custom endpoint
101
157
158
+
```curl
159
+
// Pass secret key and region using headers
160
+
curl -X POST "https://<your-custom-domain>.cognitiveservices.azure.com/translator/text/v3.0/translate?api-version=3.0&to=es" \
0 commit comments