The TranslatorClient MonoBehaviour acts as an intermediate in the case that no root / GameMaster script is being used that could provide the TextAsset with the translated strings.
Inheritance: MonoBehaviour
Beispiel #1
0
        public async Task ShouldReturnPokemonTranslatedDescription()
        {
            var baseUriPoke         = new Uri("https://pokeapi.co/api/v2/pokemon-species/");
            var baseUriTranslation  = new Uri("https://api.funtranslations.com/translate/shakespeare.json/");
            var pokemonName         = "ditto";
            var expectedDescription = "'t can freely recombine its own cellular structure to transform into other life-forms.";
            var log             = new Mock <ILogger <string> >();
            var jsonPoke        = ReadEmbeddedResource($"{pokemonName}-pokemon-species.json");
            var jsonTranslation = ReadEmbeddedResource($"{pokemonName}-translation.json");
            var mockHttp        = new MockHttpMessageHandler();

            mockHttp.When($"{baseUriPoke}{pokemonName}/").Respond("application/json", jsonPoke);
            mockHttp.When($"{baseUriTranslation}*").Respond("application/json", jsonTranslation);
            var pokeAPIClient    = new PokeAPIClient(mockHttp.ToHttpClient());
            var translatorClient = new TranslatorClient(mockHttp.ToHttpClient());
            var pokemonRetriever = new PokemonRetriever(pokeAPIClient, translatorClient);
            var controller       = new PokemonController(pokemonRetriever, log.Object);

            var response = await controller.GetAsync(pokemonName);

            var result        = (ObjectResult)response.Result;
            var pokemonResult = (Pokemon)result.Value;

            Assert.Equal(pokemonName, pokemonResult.Name);
            Assert.Equal(expectedDescription, pokemonResult.Description);
        }
Beispiel #2
0
 public SesliSozlukTranslator(IApplicationConfiguration applicationConfiguration,
                              SesliSozlukTranslatorConfiguration sesliSozlukTranslatorConfiguration, TranslatorClient translatorClient)
 {
     this.applicationConfiguration           = applicationConfiguration;
     this.sesliSozlukTranslatorConfiguration = sesliSozlukTranslatorConfiguration;
     this.translatorClient = translatorClient;
 }
Beispiel #3
0
 public string Get(string text, [FromQuery] string from, [FromQuery] string to)
 {
     using (var client = new TranslatorClient(_admAuthentication.GetAccessToken()))
     {
         return(client.TranslateAction(text, from, to));
     }
 }
Beispiel #4
0
        static ViewModelLocator()
        {
            CommonServiceLocator.ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            SimpleIoc.Default.Register(() => new NavigationServiceEx());
            SimpleIoc.Default.Register <IUserDialogs>(() => UserDialogs.Instance);

            SimpleIoc.Default.Register <IAudioService, AudioService>();

            SimpleIoc.Default.Register <ITranslatorClient>(() =>
            {
                var client = new TranslatorClient(Constants.TranslatorSubscriptionKey);
                return(client);
            });

            SimpleIoc.Default.Register <ISpeechClient>(() =>
            {
                var client = new SpeechClient(Constants.SpeechRegion, Constants.SpeechSubscriptionKey);
                return(client);
            });

            SimpleIoc.Default.Register <IMessageService>(() =>
            {
                var service = new MessageService(Constants.ServerUrl);
                return(service);
            });

            Register <MainViewModel, MainPage>();
        }
        static ViewModelLocator()
        {
            SimpleIoc.Default.Register <IUserDialogs>(() => UserDialogs.Instance);
            SimpleIoc.Default.Register <IAudioService, AudioService>();

            SimpleIoc.Default.Register <ITranslatorClient>(() =>
            {
                var client = new TranslatorClient(Constants.TranslatorSubscriptionKey);
                return(client);
            });

            SimpleIoc.Default.Register <ISpeechClient>(() =>
            {
                var client = new SpeechClient(Constants.SpeechRegion, Constants.SpeechSubscriptionKey);
                return(client);
            });

            SimpleIoc.Default.Register <IMessageService>(() =>
            {
                var service = new MessageService(Constants.ServerUrl);
                return(service);
            });

            SimpleIoc.Default.Register <MainViewModel>();
        }
 public SrEpisodeTextEnricher(TextAnalyticsClient textAnalyticsClient, TranslatorClient translatorClient, IStorage storage, ILogger <SrEpisodeTextEnricher> logger)
 {
     _textAnalyticsClient = textAnalyticsClient;
     _translatorClient    = translatorClient;
     _storage             = storage;
     _logger = logger;
 }
Beispiel #7
0
        public async Task SuccessFalseIfUnableToTranslate(HttpStatusCode httpStatusCode)
        {
            var description = "You gave Mr. Tim a hearty meal, but unfortunately what he ate made him die.";
            var mockHttp    = new MockHttpMessageHandler();

            mockHttp.When($"{_baseUri}*").Respond(httpStatusCode);
            var sut = new TranslatorClient(mockHttp.ToHttpClient());

            var response = await sut.GetTranslationAsync(description);

            Assert.False(response.IsSuccess);
        }
        //Test data: {'Type': 'M','Name': 'M_940','Content': [{'Type': 'S','Name': 'W05','Content': [ { 'E': 'N' }, { 'E': '538686' }, { 'E': '' }, { 'E': '001001' }, { 'E': '538686' }]}]}
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            var strEDITransaction = tbEdiJson.Text;
            //var json = JsonConvert.DeserializeObject(strEDITransaction);
            dynamic json = JObject.Parse(strEDITransaction);

            using (TranslatorClient EdiService = new TranslatorClient())
            {
                var testOutput = EdiService.GetEDIDocFromJSON(tbEdiJson.Text);
                MessageBox.Show("name = " + json.Name + " = " + testOutput);
            }
        }
Beispiel #9
0
        public async Task ShouldRetrieveTranslation()
        {
            var description = "You gave Mr. Tim a hearty meal, but unfortunately what he ate made him die.";
            var expected    = "Thee did giveth mr. Tim a hearty meal,  but unfortunately what he did doth englut did maketh him kicketh the bucket.";
            var json        = ReadEmbeddedResource("translation.json");
            var mockHttp    = new MockHttpMessageHandler();

            mockHttp.When($"{_baseUri}*").Respond("application/json", json);
            var sut = new TranslatorClient(mockHttp.ToHttpClient());

            var response = await sut.GetTranslationAsync(description);

            Assert.True(response.IsSuccess);
            Assert.Equal(expected, response.Value);
        }
Beispiel #10
0
        public async Task ShouldReturnNotFound()
        {
            var pokemonName      = "ditto";
            var log              = new Mock <ILogger <string> >();
            var mockHttp         = new MockHttpMessageHandler();
            var pokeAPIClient    = new PokeAPIClient(mockHttp.ToHttpClient());
            var translatorClient = new TranslatorClient(mockHttp.ToHttpClient());
            var pokemonRetriever = new PokemonRetriever(pokeAPIClient, translatorClient);
            var controller       = new PokemonController(pokemonRetriever, log.Object);

            var response = await controller.GetAsync(pokemonName);

            var result = (ObjectResult)response.Result;

            Assert.Equal(StatusCodes.Status404NotFound, result.StatusCode.Value);
        }
Beispiel #11
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            translatorClient = new TranslatorClient(ServiceKeys.TranslatorSubscriptionKey, ServiceKeys.TranslatorRegion);

            try
            {
                var languages = await translatorClient.GetLanguagesAsync();

                TargetLanguage.ItemsSource   = languages;
                TargetLanguage.SelectedIndex = 0;
            }
            catch (TranslatorServiceException ex)
            {
                var messageDialog = new MessageDialog(ex.Message);
                await messageDialog.ShowAsync();
            }

            base.OnNavigatedTo(e);
        }
Beispiel #12
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var services = builder.Services;

            services.AddTransient <ISverigesRadioApiClient>(s => SverigesRadioApiClient.CreateClient());

            services.AddTransient(x =>
            {
                var configuration  = x.GetRequiredService <IConfiguration>();
                var storageAccount = CloudStorageAccount.Parse(configuration["AzureStorage:BlobsConnectionString"]);
                return(storageAccount.CreateCloudBlobClient());
            });

            services.AddTransient(x =>
            {
                var configuration  = x.GetRequiredService <IConfiguration>();
                var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(configuration["AzureStorage:TablesConnectionString"]);
                return(storageAccount.CreateCloudTableClient(new TableClientConfiguration()));
            });

            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                return(SpeechConfig.FromSubscription(configuration["AzureSpeech:Key"], configuration["AzureSpeech:Region"]));
            });
            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                return(SpeechBatchClient.CreateApiV2Client(configuration["AzureSpeech:Key"], configuration["AzureSpeech:Hostname"], 443));
            });

            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                var credentials   = new ApiKeyServiceClientCredentials(configuration["AzureTextAnalytics:Key"]);
                return(new TextAnalyticsClient(credentials)
                {
                    Endpoint = configuration["AzureTextAnalytics:Endpoint"]
                });
            });

            services.AddTransient(x =>
            {
                var configuration = x.GetRequiredService <IConfiguration>();
                return(TranslatorClient.CreateClient(configuration["AzureTranslator:Key"], configuration["AzureTranslator:Endpoint"]));
            });

            services.AddTransient <IStorageTransfer, AzureStorageTransfer>();
            services.AddTransient <IStorage, AzureTableStorage>(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new AzureTableStorage(
                           s.GetRequiredService <CloudTableClient>(),
                           configuration["AzureStorage:EpisodeStatusesTableName"],
                           configuration["AzureStorage:EpisodesTableName"],
                           configuration["AzureStorage:EpisodeTranscriptionsTableName"],
                           configuration["AzureStorage:EpisodeTextAnalyticsTableName"],
                           configuration["AzureStorage:EpisodeSpeechTableName"]
                           ));
            });

            services.AddTransient <ISummaryStorage, SummaryAzureTableStorage>(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SummaryAzureTableStorage(
                           s.GetRequiredService <CloudTableClient>(),
                           configuration["AzureStorage:EpisodeSummaryTableName"]
                           ));
            });

            services.AddTransient <SrEpisodesLister>();
            services.AddTransient(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SrEpisodeCollector(
                           configuration["AzureStorage:AudioContainerName"],
                           s.GetRequiredService <IStorageTransfer>(),
                           s.GetRequiredService <ISverigesRadioApiClient>(),
                           s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                           s.GetRequiredService <IStorage>()
                           ));
            });

            services.AddTransient(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SrEpisodeTranscriber(
                           configuration["AzureStorage:EpisodeTranscriptionsContainerName"],
                           s.GetRequiredService <ISpeechBatchClientFactory>(),
                           s.GetRequiredService <IStorageTransfer>(),
                           s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                           s.GetRequiredService <IStorage>(),
                           s.GetRequiredService <CloudBlobClient>()
                           ));
            });

            services.AddTransient <SrEpisodeTextEnricher>();
            services.AddTransient <SrEpisodeSummarizer>();
            services.AddTransient(s =>
            {
                var configuration = s.GetRequiredService <IConfiguration>();
                return(new SrEpisodeSpeaker(
                           configuration["AzureStorage:EpisodeSpeechContainerName"],
                           s.GetRequiredService <ISpeechConfigFactory>(),
                           s.GetRequiredService <IStorage>(),
                           s.GetRequiredService <ILogger <SrEpisodeSpeaker> >(),
                           s.GetRequiredService <CloudBlobClient>()
                           ));
            });

            services.AddTransient <SrWorker>();
        }
Beispiel #13
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices((hostContext, services) =>
        {
            ServicePointManager.DefaultConnectionLimit = 100;

            services.AddSingleton <ISverigesRadioApiClient>(s => SverigesRadioApiClient.CreateClient());

            services.AddTransient(x =>
            {
                var storageAccount = CloudStorageAccount.Parse(hostContext.Configuration["AzureStorage:BlobsConnectionString"]);
                return(storageAccount.CreateCloudBlobClient());
            });

            services.AddTransient(x =>
            {
                var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(hostContext.Configuration["AzureStorage:TablesConnectionString"]);
                return(storageAccount.CreateCloudTableClient(new TableClientConfiguration()));
            });


            var azureSpeechClients = new List <SpeechBatchClientOptions>();
            hostContext.Configuration.GetSection("AzureSpeech:Clients").Bind(azureSpeechClients);
            services.AddSingleton <ISpeechConfigFactory>(x => new RoundRobinSpeechConfigFactory(azureSpeechClients));
            services.AddSingleton <ISpeechBatchClientFactory>(x => new RoundRobinSpeechBatchClientFactory(azureSpeechClients));

            services.AddTransient(x =>
            {
                var credentials = new ApiKeyServiceClientCredentials(hostContext.Configuration["AzureTextAnalytics:Key"]);
                return(new TextAnalyticsClient(credentials)
                {
                    Endpoint = hostContext.Configuration["AzureTextAnalytics:Endpoint"]
                });
            });

            services.AddTransient(x => TranslatorClient.CreateClient(hostContext.Configuration["AzureTranslator:Key"], hostContext.Configuration["AzureTranslator:Endpoint"]));

            services.AddTransient <IStorageTransfer, AzureStorageTransfer>();
            services.AddTransient <IStorage, AzureTableStorage>(s => new AzureTableStorage(
                                                                    s.GetRequiredService <CloudTableClient>(),
                                                                    hostContext.Configuration["AzureStorage:EpisodeStatusesTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodesTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodeTranscriptionsTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodeTextAnalyticsTableName"],
                                                                    hostContext.Configuration["AzureStorage:EpisodeSpeechTableName"]
                                                                    ));

            services.AddTransient <ISummaryStorage, SummaryAzureTableStorage>(s => new SummaryAzureTableStorage(
                                                                                  s.GetRequiredService <CloudTableClient>(),
                                                                                  hostContext.Configuration["AzureStorage:EpisodeSummaryTableName"]
                                                                                  ));


            services.AddTransient <IWordCountStorage, WordCounterAzureTableStorage>(s =>
            {
                var storageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount.Parse(hostContext.Configuration["AzureStorage:BlobsConnectionString"]);
                var tableClient    = storageAccount.CreateCloudTableClient(new TableClientConfiguration());

                return(new WordCounterAzureTableStorage(
                           tableClient,
                           hostContext.Configuration["AzureStorage:EpisodeWordCountTableName"]
                           ));
            });

            services.AddTransient <SrEpisodesLister>();
            services.AddTransient(s => new SrEpisodeCollector(
                                      hostContext.Configuration["AzureStorage:AudioContainerName"],
                                      s.GetRequiredService <IStorageTransfer>(),
                                      s.GetRequiredService <ISverigesRadioApiClient>(),
                                      s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                                      s.GetRequiredService <IStorage>(),
                                      hostContext.Configuration["FFMpeg:Location"]
                                      ));

            services.AddTransient(s => new SrEpisodeTranscriber(
                                      hostContext.Configuration["AzureStorage:EpisodeTranscriptionsContainerName"],
                                      s.GetRequiredService <ISpeechBatchClientFactory>(),
                                      s.GetRequiredService <IStorageTransfer>(),
                                      s.GetRequiredService <ILogger <SrEpisodeCollector> >(),
                                      s.GetRequiredService <IStorage>(),
                                      s.GetRequiredService <CloudBlobClient>()
                                      ));

            services.AddTransient <SrEpisodeTextEnricher>();
            services.AddTransient <SrEpisodeSummarizer>();
            services.AddTransient(s => new SrEpisodeSpeaker(
                                      hostContext.Configuration["AzureStorage:EpisodeSpeechContainerName"],
                                      s.GetRequiredService <ISpeechConfigFactory>(),
                                      s.GetRequiredService <IStorage>(),
                                      s.GetRequiredService <ILogger <SrEpisodeSpeaker> >(),
                                      s.GetRequiredService <CloudBlobClient>()
                                      ));

            services.AddTransient <SrEpisodeWordCounter>();

            services.AddTransient <SrWorker>();

            services.AddHostedService <Worker>();
        });