コード例 #1
0
        public async Task <TranslationResult> TranslateProvider(string ProviderName, string phrase)
        {
            ITranslationProvider provider = _translationProviders.Providers.SingleOrDefault(s => s.ProviderName == ProviderName);


            return(await provider.Translate(phrase).ConfigureAwait(false));;
        }
コード例 #2
0
 private static void TestTranslation(ITranslationProvider provider, CultureInfo src, CultureInfo tgt)
 {
     if (provider.IsSupported(src, tgt))
     {
         provider.Initialize(src, tgt, null);
         var response = provider.Translate(new TranslationRequest {
             RequestId = "1", Source = "The dog is blue.", MinimumConfidence = 50
         });
         Console.WriteLine($"Translate from {src} to {tgt}");
         Console.WriteLine($"   {response.Source}");
         if (response.IsTranslated)
         {
             Console.WriteLine($"   {response.Target}");
         }
         else
         {
             foreach (var error in response?.Errors)
             {
                 Console.WriteLine($"   {error.Message}");
             }
         }
         var suggestions = provider.Suggest(new SuggestionRequest  {
             RequestId = "1", Source = "The dog is blue.", MinimumConfidence = 50
         });
     }
 }
コード例 #3
0
        public void RenderServiceOverview(IContainer container)
        {
            while (true)
            {
                _console.WriteLine(_translationProvider.Translate("ChooseService"));

                int i = 1;

                Dictionary <int, (Type serviceType, Func <object> resolve)> choices = new Dictionary <int, (Type serviceType, Func <object> resolve)>();

                foreach ((Type serviceType, Func <object> resolve)service in container.Services)
                {
                    _console.WriteLine($"{i}) {service.serviceType.FullName}");
                    choices[i] = service;
                    i++;
                }

                string input = _console.ReadLine();

                if (input == "x")
                {
                    return;
                }

                int choice;

                try
                {
                    choice = int.Parse(input);
                }
                catch
                {
                    continue;
                }

                if (choice >= choices.Count + 1)
                {
                    _console.WriteLine($"{choice} {_translationProvider.Translate("IsOutOfRange")}");
                    continue;
                }

                var selectedService = choices[choice];

                RenderService(selectedService.serviceType, container.Resolve(selectedService.serviceType));
            }
        }