Exemple #1
0
        private ITranslatorService CreateTranslatorService(Tenant tenant, ITokenRefresherWithServiceClient nexusTokenRefresher)
        {
            var valueTranslatorUrl = Configuration["Nexus:ValueTranslatorUrl"];
            var translateClient    = new TranslateClient(valueTranslatorUrl, tenant, nexusTokenRefresher.GetServiceClient());

            return(new TranslatorService(translateClient));
        }
        public void SetUp()
        {
#if SILVERLIGHT
            this.Client = new TranslateClient();
#else
            this.Client = new TranslateClient(@"http://code.google.com/p/google-api-for-dotnet/");
#endif
        }
        public void SetUp()
        {
#if SILVERLIGHT
            this.Client = new TranslateClient();
#else
            this.Client = new TranslateClient(@"http://code.google.com/p/google-api-for-dotnet/");
#endif
        }
Exemple #4
0
 public async Task <IList <ResponseBody> > Index([FromBody] TranslateRequest translate)
 {
     try
     {
         // Create a call with the configuration from a client.
         var translateClient = new TranslateClient(translate.CognitiveServicesConfig);
         return(await translateClient.TranslateAsync(translate.RequestContents, translate.Options));
     }
     catch (Exception e)
     {
         _logger.LogError(default(EventId), e, "Error!!!!");
         throw e;
     }
 }
        public HttpResponseMessage Post([FromBody] TranslateRequest jsonbody)
        {
            String            title = "";
            TranslateResponse trans = new TranslateResponse();

            try
            {
                TranslateClient client = new TranslateClient("");
                Language        lang1  = Language.Japanese;
                Language        lang2  = Language.Vietnamese;
                title = client.Translate(jsonbody.text, "ja", "vi");
            }
            catch { }
            trans.title = title;
            return(Request.CreateResponse(HttpStatusCode.OK, trans));
        }
        public string TranslateYourText(string text, string langFrom, string langTo)
        {
            string translated = "";

            Console.WriteLine(text);
            try
            {
                TranslateClient client = new TranslateClient("");
                Language        lang1  = Language.English;
                Language        lang2  = Language.Arabic;
                foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
                {
                    if (ci.EnglishName == langFrom)
                    {
                        lang1 = ci.Name;
                    }
                    if (ci.EnglishName == langTo)
                    {
                        lang2 = ci.Name;
                    }
                }
                if (Autodetect == true)
                {
                    string from;
                    translated = client.TranslateAndDetect(text, lang2.ToString(), out from);
                    foreach (string options in Language.GetEnums())
                    {
                        if (options == from)
                        {
                            CultureInfo ci = new CultureInfo(from);
                            combo_from.Text = ci.EnglishName;
                        }
                    }
                }
                else
                {
                    translated = client.Translate(text, lang1, lang2, TranslateFormat.Text);
                    Console.WriteLine(translated);
                }
                return(translated);
            }
            catch
            {
                MessageBox.Show(this, "Check Your Internet Connection", "Try Again Please", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(translated);
            }
        }
        private static void RegisterDataAccessLayer(ContainerBuilder builder)
        {
            var organization = ConfigurationManager.AppSettings["Organization"];
            var environment  = ConfigurationManager.AppSettings["Environment"];
            var tenant       = new Tenant(organization, environment);

            builder.RegisterInstance(tenant).As <ITenant>();

            var authServiceCredentials = new AuthenticationCredentials {
                ClientId = "user", ClientSecret = "pwd"
            };

            var tokenRefresher = RegisterAuthentication(builder, tenant, authServiceCredentials);

            RegisterLogging(tokenRefresher);


            var authenticationService = new AuthenticationService(ConfigurationManager.AppSettings["Authentication.Url"], tenant,
                                                                  authServiceCredentials);

            builder.RegisterInstance(authenticationService).As <IAuthenticationService>();

            var translateClient = new TranslateClient(ConfigurationManager.AppSettings["KeyTranslator.Url"], tenant,
                                                      tokenRefresher.GetServiceClient());

            builder.RegisterInstance(translateClient).As <ITranslateClient>();

            var customerMasterClient = new CustomerMasterClient(ConfigurationManager.AppSettings["CustomerMaster.Url"],
                                                                tokenRefresher.GetServiceClient());

            builder.RegisterInstance(customerMasterClient).As <ICustomerMasterClient>();

            var StatisticsClient = new StatisticsClient(ConfigurationManager.AppSettings["Statistics.Url"],
                                                        tokenRefresher.GetServiceClient());

            builder.RegisterInstance(StatisticsClient).As <IStatisticsClient>();

            var visualNotificationClient = new VisualNotificationClient(ConfigurationManager.AppSettings["VisualNotification.Url"],
                                                                        tokenRefresher.GetServiceClient());

            builder.RegisterInstance(visualNotificationClient).As <IVisualNotificationClient>();
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            TranslateCommand.Initialize(this);
            ToggleAutoTranslateCommand.Initialize(this);
            base.Initialize();

            //Load settting
            Settings.ReloadSetting((OptionPageGrid)GetDialogPage(typeof(OptionPageGrid)));

            //Create client
            TranslateClient = new TranslateClient(Settings);

            DTE            = (DTE2)GetService(typeof(DTE));
            Events         = DTE.Events;
            DocumentEvents = Events.DocumentEvents;
            WindowEvents   = Events.WindowEvents;

            DocumentEvents.DocumentOpened += DocumentEvents_DocumentOpened;
            DocumentEvents.DocumentSaved  += DocumentEvents_DocumentSaved;
            WindowEvents.WindowActivated  += WindowEvents_WindowActivated;
        }
Exemple #9
0
        public bool OnNewChatMessageFromWorld(OSChatMessage c, out OSChatMessage newc)
        {
            string[]           operators = c.Message.Split(' ');
            TranslatorUserInfo UInfo     = null;

            if (operators[0].StartsWith("translate", StringComparison.CurrentCultureIgnoreCase))
            {
                // Example to turn on translator
                // translator en >> fr         translator en > fr
                // translator fr << en         translator fr < en

                if (operators[2].Contains(">")) //Covers > and >>,
                {
                    UserInfos[c.SenderUUID] = new TranslatorUserInfo()
                    {
                        enabled = true,
                        From    = Aurora.GoogleAPIs.Language.GetValue(operators[1]),
                        To      = Aurora.GoogleAPIs.Language.GetValue(operators[3])
                    };
                }
                else if (operators[2].Contains("<")) //Covers < and <<,
                {
                    UserInfos[c.SenderUUID] = new TranslatorUserInfo()
                    {
                        enabled = true,
                        From    = Aurora.GoogleAPIs.Language.GetValue(operators[3]),
                        To      = Aurora.GoogleAPIs.Language.GetValue(operators[1])
                    };
                }
            }
            else if (c.Message.StartsWith("translator settings", StringComparison.CurrentCultureIgnoreCase))
            {
                if (UserInfos.TryGetValue(c.SenderUUID, out UInfo))
                {
                    if (operators[2] == "enabled")
                    {
                        UInfo.enabled = bool.Parse(operators[3]);
                    }
                    if (operators[2] == "showold")
                    {
                        UInfo.ShowNonTranslated = bool.Parse(operators[3]);
                    }
                }
            }
            else if (c.Message.StartsWith("translator help", StringComparison.CurrentCultureIgnoreCase))
            {
                c.Message = "Translate: \n" +
                            "translate from >> to  - translates from language 'from' into language 'to'\n" +
                            "Settings:\n" +
                            "translator settings enabled true/false - enables the translator\n" +
                            "translator settings showold true/false - shows the original chat\n" +
                            "Languages\n";
                foreach (Aurora.GoogleAPIs.Language lang in Aurora.GoogleAPIs.Language.TranslatableList)
                {
                    c.Message += lang.Name + " - " + lang.Value + "\n";
                }
            }
            else if (UserInfos.TryGetValue(c.SenderUUID, out UInfo))
            {
                //If enabled, ask google translator about it
                if (UInfo.enabled)
                {
                    TranslateClient tc         = new TranslateClient("http://ajax.googleapis.com/ajax/services/language/translate");
                    string          translated = "";
                    try
                    {
                        translated = tc.Translate(c.Message, UInfo.From.Value, UInfo.To.Value);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("[Aurora Translator]: Error in requesting translation, " + ex.ToString());
                    }
                    if (!UInfo.ShowNonTranslated)
                    {
                        c.Message = translated;
                    }
                    else
                    {
                        c.Message = translated + " (" + c.Message + ")";
                    }
                }
            }
            newc = c;
            return(true);
        }
 public TranslateProvider(string referrer)
 {
     _client = new TranslateClient(referrer);
 }
Exemple #11
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req,
            TraceWriter log)
        {
            // parse query parameter
            var message = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => string.Compare(q.Key, "content", true) == 0)
                          .Value;

            var translationClient = new TranslateClient();
            var translationTask   = translationClient.GetTranslation(message);

            var from = req.GetQueryNameValuePairs()
                       .FirstOrDefault(q => string.Compare(q.Key, "from", true) == 0)
                       .Value;

            var luisClient = new LuisClient();
            var luisData   = await luisClient.AnalyseText(message);

            // bold out entity pieces in original message
            var content = message;

            if (luisData.Entities != null)
            {
                var counter = 0;
                foreach (var entity in luisData.Entities)
                {
                    content = content.Insert(entity.StartIndex + counter++, "*");
                    content = content.Insert(entity.EndIndex + counter++ + 1, "*");
                }
            }

            var searchKeywords = string.Join(" ", luisData.Entities.Select(x => x.Entity));

            var client = new HttpClient();

            SendGiphinMessage(client, from, searchKeywords);
            SentimentMessage(client, from, luisData, searchKeywords);

            var translations = await translationTask;

            foreach (var translation in translations)
            {
                SendTextMessage(client, from, $"It seemed like time to learn {translation.Key}, you said: {translation.Value}");
            }

            var random        = new Random();
            var isTranslation = random.Next(5) > 2;
            var imageUrl      = await SendSlackMessage(client, content, searchKeywords, translations, isTranslation);

            var soundUrl = await SendSlackSoundMessage(client, content, searchKeywords);

            GetSpotifyTracks(client, content, searchKeywords);


            const string   EndpointUrl = "https://hackmcr.documents.azure.com:443/";
            const string   PrimaryKey  = "TrMpg5jbBZN1MWJnZ68SqIbv2sgkWm1G23xrEhBdpWFFa5KYMQl6XpCVlzxN1xauA45w0sDx5iHEgC4NKqSn3w==";
            DocumentClient docClient   = new DocumentClient(new Uri(EndpointUrl), PrimaryKey);
            var            response    = await docClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("ToDoList", "Messages"),
                                                                             new
            {
                Message        = message,
                SearchKeywords = searchKeywords,
                Sound          = $"https:{soundUrl}",
                Gif            = imageUrl,
                Sentiment      = luisData.SentimentAnalysis.Label,
                Translations   = translations,
                Timestamp      = DateTime.Now
            });

            return(req.CreateResponse(HttpStatusCode.OK, content));
        }
Exemple #12
0
        public async Task <IList <ResponseBody> > Index([FromBody] Translate translate)
        {
            var translateClient = new TranslateClient(translate.CognitiveServicesConfig);

            return(await translateClient.TranslateAsync(translate.RequestContents, translate.Options));
        }
Exemple #13
0
 public Translator()
 {
     this.log    = LogManager.GetLogger("Translator");
     this.client = new TranslateClient("http://www.mysite.com");
 }