From 0cd2209cfb6e61704b49d5e78a527e960a02b99c Mon Sep 17 00:00:00 2001 From: Davide Conti Date: Tue, 23 Aug 2022 11:33:15 +0200 Subject: [PATCH] Add language detection support --- src/Model/DetectedLanguage.cs | 13 +++++++++++++ src/ModernMTService.cs | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/Model/DetectedLanguage.cs diff --git a/src/Model/DetectedLanguage.cs b/src/Model/DetectedLanguage.cs new file mode 100644 index 0000000..ab26a13 --- /dev/null +++ b/src/Model/DetectedLanguage.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace ModernMT.Model +{ + public class DetectedLanguage : Model + { + [JsonProperty("billedCharacters")] + public int BilledCharacters { get; set; } + + [JsonProperty("detectedLanguage")] + public string Language { get; set; } + } +} diff --git a/src/ModernMTService.cs b/src/ModernMTService.cs index 22d395c..fe20a45 100644 --- a/src/ModernMTService.cs +++ b/src/ModernMTService.cs @@ -27,6 +27,17 @@ public List ListSupportedLanguages() return _client.Send>("get", "/translate/languages"); } + public DetectedLanguage DetectLanguage(string q, string format = null) + { + var data = new Dictionary + { + {"q", q}, + {"format", format} + }; + + return _client.Send("get", "/translate/detect", data); + } + public Translation Translate(string source, string target, string q, long[] hints = null, string contextVector = null, TranslateOptions options = null) {