Esempio n. 1
0
        private static String GoogleTranslateText(String text)
        {
            TranslationResult gresult;
            TranslateService  service = new TranslateService(new BaseClientService.Initializer {
                ApiKey = googleCloudKey
            });
            TranslationClientImpl gclient = new TranslationClientImpl(service, TranslationModel.ServiceDefault);

            gresult = gclient.TranslateText(text, LanguageCodes.ChineseTraditional);
            return(gresult.TranslatedText);
        }
        public void NonMatchingTranslateResultCount()
        {
            var service = new FakeTranslateService();
            var client  = new TranslationClientImpl(service);
            var inputs  = new string[] { "a", "b" };
            var request = service.Translations.List(new Repeatable <string>(inputs), "en");

            request.Format = FormatEnum.Text;
            var response = new TranslationsListResponse
            {
                // Content is irrelevant; we shouldn't get that far
                Translations = new List <TranslationsResource> {
                    new TranslationsResource()
                }
            };

            service.ExpectRequest(request, response);
            Assert.Throws <InvalidOperationException>(() => client.TranslateText(inputs, "en"));
        }
        public void NonMatchingTranslateResultCount()
        {
            var service = new FakeTranslateService();
            var client  = new TranslationClientImpl(service);
            var inputs  = new string[] { "a", "b" };
            var body    = new TranslateTextRequest
            {
                Q      = inputs,
                Format = "text",
                Target = "en"
            };
            var request  = service.Translations.Translate(body);
            var response = new TranslationsListResponse
            {
                // Content is irrelevant; we shouldn't get that far
                Translations = new List <TranslationsResource> {
                    new TranslationsResource()
                }
            };

            service.ExpectRequest(request, response);
            Assert.Throws <InvalidOperationException>(() => client.TranslateText(inputs, "en"));
        }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            var service = new TranslateService(new BaseClientService.Initializer {
                ApiKey = GoogleApiKey
            });
            var client  = new TranslationClientImpl(service);
            var results = new List <string>();

            string line;
            var    file = new StreamReader(ToolbarPath);

            while ((line = file.ReadLine()) != null)
            {
                Console.WriteLine(line);

                if (line.Contains("locale_1033"))
                {
                    results.Add(line);

                    var onlyText = RemoveTags(line);

                    var translated = client.TranslateText(onlyText, "es", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1034"));

                    translated = client.TranslateText(onlyText, "fr", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1036"));

                    translated = client.TranslateText(onlyText, "it", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1040"));

                    translated = client.TranslateText(onlyText, "pt", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "2070"));

                    translated = client.TranslateText(onlyText, "de", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1031"));

                    translated = client.TranslateText(onlyText, "zh-cn", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "2052"));

                    translated = client.TranslateText(onlyText, "zh-tw", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1028"));

                    translated = client.TranslateText(onlyText, "ja", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1041"));

                    translated = client.TranslateText(onlyText, "cs", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1029"));

                    translated = client.TranslateText(onlyText, "ru", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1049"));

                    translated = client.TranslateText(onlyText, "pl", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1045"));

                    translated = client.TranslateText(onlyText, "ko", "en", null);
                    results.Add(AddTags(translated.TranslatedText, "1042"));
                }
                else
                {
                    results.Add(line);
                }
            }

            file.Close();
            var translatedRui = new StreamWriter(ToolbarPathCopy);

            foreach (var lineTranslated in results)
            {
                translatedRui.WriteLine(lineTranslated);
            }

            translatedRui.Close();
        }