示例#1
0
 /// <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="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>
 /// <param name="userCustomDictonaries">Custom languages dictionary object, used to store all the different languages dictionaries
 /// configured by the user to overwrite the translator output to certain vocab by the custom dictionary translation.</param>
 /// <param name="languageStateProperty">A Property Accessor for for getting the users active language.</param>
 /// <param name="toUserLanguage">Indicates whether to translate messages sent from the bot into the user's language.</param>
 /// <remarks>Each pattern the <paramref name="patterns"/> describes an entity that should not be translated.
 /// For example, in French <c>je m’appelle ([a-z]+)</c>, which will avoid translation of anything coming after je m’appelle.</remarks>
 /// <param name="httpClient">An alternate HTTP client to use.</param>
 public TranslationMiddleware(string[] nativeLanguages, string translatorKey, Dictionary <string, List <string> > patterns, CustomDictionary userCustomDictonaries, IStatePropertyAccessor <string> languageStateProperty, bool toUserLanguage = false, HttpClient httpClient = null)
     : this(nativeLanguages, translatorKey, patterns, userCustomDictonaries, toUserLanguage, httpClient)
 {
     _languageStateProperty = languageStateProperty ?? throw new ArgumentNullException(nameof(languageStateProperty));
 }
 /// <summary>
 /// Creates a new <see cref="TranslationMiddleware"/> object.
 /// </summary>
 /// <param name="nativeLanguages">The 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>
 /// /// <param name="userCustomDictonaries">Custom languages dictionary object, used to store all the different languages dictionaries
 /// configured by the user to overwrite the translator output to certain vocab by the custom dictionary translation.</param>
 /// <param name="toUserLanguage">Indicates whether to translate messages sent from the bot into the user's language.</param>
 /// <remarks>Each pattern the <paramref name="patterns"/> describes an entity that should not be translated.
 /// For example, in French <c>je m’appelle ([a-z]+)</c>, which will avoid translation of anything coming after je m’appelle.</remarks>
 public TranslationMiddleware(string[] nativeLanguages, string translatorKey, Dictionary <string, List <string> > patterns, CustomDictionary userCustomDictonaries, bool toUserLanguage = false) : this(nativeLanguages, translatorKey, toUserLanguage)
 {
     if (patterns != null)
     {
         this._patterns = patterns;
     }
     if (userCustomDictonaries != null)
     {
         this._userCustomDictonaries = userCustomDictonaries;
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TranslationMiddleware"/> class.
        /// </summary>
        /// <param name="nativeLanguages">The 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>
        /// /// <param name="userCustomDictonaries">Custom languages dictionary object, used to store all the different languages dictionaries
        /// configured by the user to overwrite the translator output to certain vocab by the custom dictionary translation.</param>
        /// <param name="toUserLanguage">Indicates whether to translate messages sent from the bot into the user's language.</param>
        /// <param name="defaultLocale">Default locale to use when underlying user locale is undefined.</param>
        /// <remarks>Each pattern the <paramref name="patterns"/> describes an entity that should not be translated.
        /// For example, in French <c>je m’appelle ([a-z]+)</c>, which will avoid translation of anything coming after je m’appelle.</remarks>
        /// <param name="httpClient">An alternate HTTP client to use.</param>
        public TranslationMiddleware(string[] nativeLanguages, string translatorKey, Dictionary <string, List <string> > patterns, CustomDictionary userCustomDictonaries, bool toUserLanguage = false, HttpClient httpClient = null, string defaultLocale = "en")
            : this(nativeLanguages, translatorKey, toUserLanguage, httpClient, defaultLocale)
        {
            if (patterns != null)
            {
                this._patterns = patterns;
            }

            if (userCustomDictonaries != null)
            {
                this._userCustomDictonaries = userCustomDictonaries;
            }
        }