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
# Quickstart: Use the Translator Text API to detect text language using C#
16
16
17
-
In this quickstart, you'll learn how to detect the language of provided text using .NET Core and the Translator Text REST API.
17
+
In this quickstart, you'll learn how to detect the language of provided text using .NET Core, C# 7.1 or later, and the Translator Text REST API.
18
18
19
19
This quickstart requires an [Azure Cognitive Services account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account) with a Translator Text resource. If you don't have an account, you can use the [free trial](https://azure.microsoft.com/try/cognitive-services/) to get a subscription key.
*[Visual Studio](https://visualstudio.microsoft.com/downloads/), [Visual Studio Code](https://code.visualstudio.com/download), or your favorite text editor
@@ -42,6 +43,18 @@ Next, you'll need to install Json.Net. From your project's directory, run:
This quickstart requires C# 7.1 or later. There are a few ways to change the C# version for your project. In this guide, we'll show you how to adjust the `detect-sample.csproj` file. For all available options, such as changing the language in Visual Studio, see [Select the C# language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version).
49
+
50
+
Open your project, then open `detect-sample.csproj`. Make sure that `LangVersion` is set to 7.1 or later. If there isn't a property group for the language version, add these lines:
51
+
52
+
```xml
53
+
<PropertyGroup>
54
+
<LangVersion>7.1</LangVersion>
55
+
</PropertyGroup>
56
+
```
57
+
45
58
## Add required namespaces to your project
46
59
47
60
The `dotnet new console` command that you ran earlier created a project, including `Program.cs`. This file is where you'll put your application code. Open `Program.cs`, and replace the existing using statements. These statements ensure that you have access to all the types required to build and run the sample app.
@@ -50,15 +63,42 @@ The `dotnet new console` command that you ran earlier created a project, includi
50
63
usingSystem;
51
64
usingSystem.Net.Http;
52
65
usingSystem.Text;
66
+
usingSystem.Threading.Tasks;
67
+
// Install Newtonsoft.Json with NuGet
53
68
usingNewtonsoft.Json;
54
69
```
55
70
71
+
## Create classes for the JSON response
72
+
73
+
Next, we're going to create a class that's used when deserializing the JSON response returned by the Translator Text API.
74
+
75
+
```csharp
76
+
/// <summary>
77
+
/// The C# classes that represents the JSON returned by the Translator Text API.
## Create a function to detect the source text's language
57
97
58
-
Within the `Program` class, create a function called `Detect`. This class encapsulates the code used to call the Detect resource and prints the result to console.
98
+
Within the `Program` class, create a function called `DetectTextRequest()`. This class encapsulates the code used to call the Detect resource and prints the result to console.
Copy file name to clipboardExpand all lines: articles/cognitive-services/Translator/quickstart-csharp-sentences.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,13 +8,13 @@ manager: nitinme
8
8
ms.service: cognitive-services
9
9
ms.subservice: translator-text
10
10
ms.topic: quickstart
11
-
ms.date: 06/04/2019
11
+
ms.date: 06/13/2019
12
12
ms.author: erhopf
13
13
---
14
14
15
15
# Quickstart: Use the Translator Text API to determine sentence length using C#
16
16
17
-
In this quickstart, you'll learn how to determine sentence lengths using .NET Core and the Translator Text API.
17
+
In this quickstart, you'll learn how to determine sentence lengths using .NET Core, C# 7.1 or later, and the Translator Text API.
18
18
19
19
This quickstart requires an [Azure Cognitive Services account](https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account) with a Translator Text resource. If you don't have an account, you can use the [free trial](https://azure.microsoft.com/try/cognitive-services/) to get a subscription key.
20
20
@@ -91,7 +91,7 @@ public class DetectedLanguage
91
91
92
92
## Create a function to determine sentence length
93
93
94
-
Within the `Program` class, create a function called `BreakSentence`. This function takes four arguments: `subscriptionKey`, `host`, `route`, and `inputText`.
94
+
Within the `Program` class, create a function called `BreakSentence()`. This function takes four arguments: `subscriptionKey`, `host`, `route`, and `inputText`.
Copy file name to clipboardExpand all lines: articles/cognitive-services/Translator/quickstart-csharp-translate.md
+2-2Lines changed: 2 additions & 2 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: quickstart
11
-
ms.date: 06/04/2019
11
+
ms.date: 06/13/2019
12
12
ms.author: erhopf
13
13
---
14
14
@@ -118,7 +118,7 @@ public class SentenceLength
118
118
119
119
## Create a function to translate text
120
120
121
-
Within the `Program` class, create an asynchronous function called `TranslateTextRequest`. This function takes four arguments: `subscriptionKey`, `host`, `route`, and `inputText`.
121
+
Within the `Program` class, create an asynchronous function called `TranslateTextRequest()`. This function takes four arguments: `subscriptionKey`, `host`, `route`, and `inputText`.
122
122
123
123
```csharp
124
124
// This sample requires C# 7.1 or later for async/await.
Copy file name to clipboardExpand all lines: articles/cognitive-services/Translator/quickstart-csharp-transliterate.md
+2-2Lines changed: 2 additions & 2 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: quickstart
11
-
ms.date: 06/04/2019
11
+
ms.date: 06/13/2019
12
12
ms.author: erhopf
13
13
---
14
14
@@ -85,7 +85,7 @@ public class TransliterationResult
85
85
86
86
## Create a function to transliterate text
87
87
88
-
Within the `Program` class, create an asynchronous function called `TransliterateTextRequest`. This function takes four arguments: `subscriptionKey`, `host`, `route`, and `inputText`.
88
+
Within the `Program` class, create an asynchronous function called `TransliterateTextRequest()`. This function takes four arguments: `subscriptionKey`, `host`, `route`, and `inputText`.
0 commit comments