Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions libraries/Microsoft.Bot.Builder.Ai.Translation/AzureAuthToken.cs

This file was deleted.

22 changes: 22 additions & 0 deletions libraries/Microsoft.Bot.Builder.Ai.Translation/Model/Alignment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// An object with a single string property named proj, which maps input text to translated text.
/// Alignment is returned as a string value of the following format:
/// <c>[[SourceTextStartIndex]:[SourceTextEndIndex]–[TgtTextStartIndex]:[TgtTextEndIndex]]</c>.
/// The colon separates start and end index, the dash separates the languages,
/// and space separates the words. One word may align with zero, one, or multiple words
/// in the other language, and the aligned words may be non-contiguous. When no alignment
/// information is available, the alignment element will be empty.
/// </summary>
internal class Alignment
{
[JsonProperty("proj")]
public string Projection { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// Detected language with Translator API v3.
/// </summary>
internal class DetectedLanguageModel
{
[JsonProperty("language")]
public string Language { get; set; }

[JsonProperty("score")]
public float Score { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// Error information from Translator API v3.
/// </summary>
internal class ErrorMessage
{
[JsonProperty("code")]
public int Code { get; set; }

[JsonProperty("message")]
public string Message { get; set; }
}
}
16 changes: 16 additions & 0 deletions libraries/Microsoft.Bot.Builder.Ai.Translation/Model/ErrorModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// Standard error from Translator API v3.
/// </summary>
internal class ErrorModel
{
[JsonProperty("error")]
public ErrorMessage Error { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// Represents the sentence boundaries in the input and output texts.
/// </summary>
internal class SentencesLength
{
[JsonProperty("srcSentLen")]
public IEnumerable<int> Source { get; set; }

[JsonProperty("transSentLen")]
public IEnumerable<int> Translation { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// Array of translated results from Translator API v3.
/// </summary>
internal class TranslatedResult
{
[JsonProperty("translations")]
public IEnumerable<TranslationModel> Translations { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// Translation result from Translator API v3.
/// </summary>
internal class TranslationModel
{
[JsonProperty("text")]
public string Text { get; set; }

[JsonProperty("to")]
public string To { get; set; }

[JsonProperty("alignment")]
public Alignment Alignment { get; set; }

[JsonProperty("sentLen")]
public SentencesLength SentencesLength { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Bot.Builder.Ai.Translation.Model
{
/// <summary>
/// Model for translator request to Translator API v3.
/// </summary>
internal class TranslatorRequestModel
{
public string Text { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public TranslationMiddleware(string[] nativeLanguages, string translatorKey, Dic
/// <summary>
/// Initializes a new instance of the <see cref="TranslationMiddleware"/> class.
/// </summary>
/// <param name="nativeLanguages">List of languages supported by your app</param>
/// <param name="nativeLanguages">List of languages supported by your app.</param>
/// <param name="translatorKey">Your subscription key for the Microsoft Translator Text API.</param>
/// <param name="patterns">List of regex patterns, indexed by language identifier,
/// that can be used to flag text that should not be translated.</param>
Expand All @@ -100,7 +100,7 @@ public TranslationMiddleware(string[] nativeLanguages, string translatorKey, Dic
/// </summary>
/// <param name="context">The context object for this turn.</param>
/// <param name="next">The delegate to call to continue the bot middleware pipeline.</param>
/// <param name="cancellationToken">cancellationToken</param>
/// <param name="cancellationToken">cancellationToken.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public virtual async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
{
Expand Down Expand Up @@ -194,8 +194,8 @@ private void InitializePostProcessors()
/// <summary>
/// Applies all the attached post processors to the translated messages.
/// </summary>
/// <param name="translatedDocuments">List of <see cref="TranslatedDocument"/> represent the output of the translator module</param>
/// <param name="languageId">Current language id</param>
/// <param name="translatedDocuments">List of <see cref="TranslatedDocument"/> represent the output of the translator module.</param>
/// <param name="languageId">Current language id.</param>
private void PostProcesseDocuments(List<TranslatedDocument> translatedDocuments, string languageId)
{
if (attachedPostProcessors == null)
Expand All @@ -219,7 +219,7 @@ private void PostProcesseDocuments(List<TranslatedDocument> translatedDocuments,
/// <param name="message">The activity containing the text to translate.</param>
/// <param name="sourceLanguage">An identifier for the language to translate from.</param>
/// <param name="targetLanguage">An identifier for the language to translate to.</param>
/// <param name="inNativeLanguages">should only use native langauges</param>
/// <param name="inNativeLanguages">should only use native langauges.</param>
/// <returns>A task that represents the work queued to execute.</returns>
/// <remarks>When the task completes successfully, the <see cref="Activity.Text"/> property
/// of the message contains the translated text.</remarks>
Expand Down
Loading