Esempio n. 1
0
        /// <summary>
        /// Translates a single string with the help of the MT service.
        /// </summary>
        /// <param name="options">Current plugin configuration.</param>
        /// <param name="input">The string to translate.</param>
        /// <param name="srcLangCode">The source language code.</param>
        /// <param name="trgLangCode">The target language code.</param>
        /// <returns>The translated string.</returns>
        public static List <string> Translate(TartuNLPOptions options, List <string> input, string srcLangCode, string trgLangCode)
        {
            if (trgLangCode.Contains("-"))
            {
                trgLangCode = trgLangCode.Split('-')[0];
            }
            if (srcLangCode.Contains("-"))
            {
                srcLangCode = srcLangCode.Split('-')[0];
            }

            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("x-api-key", options.SecureSettings.Auth);
            client.DefaultRequestHeaders.Add("application", "MemoQ");
            var content = new Input
            {
                text   = input,
                src    = srcLangCode,
                tgt    = trgLangCode,
                domain = options.GeneralSettings.SelectedDomainCode
            };
            var json         = Newtonsoft.Json.JsonConvert.SerializeObject(content);
            var strContent   = new StringContent(json, Encoding.UTF8, "application/json");
            var response     = client.PostAsync(options.SecureSettings.URL, strContent).Result;
            var JSONResponse = new JavaScriptSerializer().Deserialize <JSONResponse>(response.Content.ReadAsStringAsync().Result);

            return(JSONResponse.result);
        }
Esempio n. 2
0
 /// <summary>
 /// Stores a single string pair as translation with the help of the dummy MT service.
 /// </summary>
 /// <param name="tokenCode">The token code.</param>
 /// <param name="source">The source string.</param>
 /// <param name="target">The target string.</param>
 /// <param name="srcLangCode">The source language code.</param>
 /// <param name="trgLangCode">The target language code.</param>
 public static void StoreTranslation(TartuNLPOptions options, string source, string target, string srcLangCode, string trgLangCode)
 {
     // Always dispose allocated resources
     //var proxy = getNewProxy();
     //using (proxy as IDisposable)
     //{
     //    proxy.StoreTranslation(GetTokenCode(options), source, target, srcLangCode, trgLangCode);
     //}
 }
Esempio n. 3
0
 /// <summary>
 /// Stores multiple string pairs as translation with the help of the dummy MT service.
 /// </summary>
 /// <param name="tokenCode">The token code.</param>
 /// <param name="sources">The source strings.</param>
 /// <param name="targets">The target strings.</param>
 /// <param name="srcLangCode">The source language code.</param>
 /// <param name="trgLangCode">The target language code.</param>
 /// <returns>The indices of the translation units that were succesfully stored.</returns>
 public static int[] BatchStoreTranslation(TartuNLPOptions options, List <string> sources, List <string> targets, string srcLangCode, string trgLangCode)
 {
     //// Always dispose allocated resources
     //var proxy = getNewProxy();
     //using (proxy as IDisposable)
     //{
     //    return proxy.BatchStoreTranslation(GetTokenCode(options), sources, targets, srcLangCode, trgLangCode);
     //}
     return(new int[0]);
 }
Esempio n. 4
0
        public TartuNLPConfigForm(TartuNLPOptions options, Sdl.LanguagePlatform.Core.LanguagePair[] languagePairs)
        {
            string sSourceCulture = languagePairs[0].SourceCultureName.ToLower();
            string sTargetCulture = languagePairs[0].TargetCultureName.ToLower();

            Options = options;
            InitializeComponent();
            SendMessage(tbURL.Handle, EM_SETCUEBANNER, 0, "https://api.tartunlp.ai/v1.2/translate");
            SendMessage(tbAuth.Handle, EM_SETCUEBANNER, 0, "public");
            tbURL.Text  = "https://api.tartunlp.ai/v1.2/translate";
            tbAuth.Text = "public";
        }
Esempio n. 5
0
        public TranslationProviderDisplayInfo GetDisplayInfo(Uri translationProviderUri, string translationProviderState)
        {
            var options = new TartuNLPOptions(translationProviderUri);
            var info    = new TranslationProviderDisplayInfo();

            info.Name                    = String.Format("{0} ({1})", TypeName, options.SelectedDomainName);
            info.TooltipText             = TypeDescription;
            info.TranslationProviderIcon = PluginResources.icon;
            info.SearchResultImage       = PluginResources.symbol;

            return(info);
        }
Esempio n. 6
0
        /// <summary>
        /// Translates multiple strings with the help of the dummy MT service.
        /// </summary>
        /// <param name="tokenCode">The token code.</param>
        /// <param name="input">The strings to translate.</param>
        /// <param name="srcLangCode">The source language code.</param>
        /// <param name="trgLangCode">The target language code.</param>
        /// <returns>The translated strings.</returns>
        public static List <String> BatchTranslate(TartuNLPOptions options, List <string> input, string srcLangCode, string trgLangCode)
        {
            if (trgLangCode.Contains("-"))
            {
                trgLangCode = trgLangCode.Split('-')[0];
            }

            HttpClient client  = new HttpClient();
            var        content = new BatchInput();

            content.text = input;
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(content);
            //var content = "{'text':" + Newtonsoft.Json.JsonConvert.SerializeObject(input) + "}";

            HttpResponseMessage response = client.PostAsync(options.SecureSettings.URL + "?auth=" + options.SecureSettings.Auth + "&olang=" + trgLangCode + "&odomain=" + options.GeneralSettings.SelectedDomain, new StringContent(json, Encoding.UTF8, "application/json")).Result;
            string test         = response.Content.ReadAsStringAsync().Result;
            var    JSONResponse = new JavaScriptSerializer().Deserialize <JSONResponseBatch>(response.Content.ReadAsStringAsync().Result);

            return(JSONResponse.result);
        }
 public TartuNLPProviderLanguageDirection(TartuNLPProvider provider, LanguagePair languages)
 {
     _provider          = provider;
     _languageDirection = languages;
     _options           = _provider.Options;
 }
Esempio n. 8
0
 public TartuNLPEngine(string srcLangCode, string trgLangCode, TartuNLPOptions options)
 {
     this.srcLangCode = srcLangCode;
     this.trgLangCode = trgLangCode;
     this.options     = options;
 }
Esempio n. 9
0
 public TartuNLPProvider(TartuNLPOptions options)
 {
     Options = options;
 }
Esempio n. 10
0
 public TartuNLPConfigForm(TartuNLPOptions options)
 {
     Options = options;
     InitializeComponent();
 }
Esempio n. 11
0
        /// <summary>
        /// Calls the web service's login method.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="password">The password.</param>
        /// <returns>The token code.</returns>
        //public static string Login(string userName, string password)
        //{
        //    // Always dispose allocated resources
        //    var proxy = getNewProxy();
        //    using (proxy as IDisposable)
        //    {
        //        return proxy.Login(userName, password);
        //    }
        //}

        /// <summary>
        /// Lists the supported languages of the dummy MT service.
        /// </summary>
        /// <returns>The list of the supported languages.</returns>
        public static List <string> ListSupportedLanguages(TartuNLPOptions options)
        {
            return(options.GeneralSettings.SupportedLanguages.ToList());
        }