コード例 #1
0
        public void ETSApi_FetchTranslationNoTags_ValidTranslation()
        {
            var xliffDocument = new Xliff(engFraLP.SourceCulture, engFraLP.TargetCulture);

            xliffDocument.AddSourceText(StringResource.BasicText);

            var translatedXliffText = ETSTranslatorHelper.GetTranslation(apiKeyTranslationOptions, engFraLP, xliffDocument);
            var translatedXliff     = Sdl.Community.Toolkit.LanguagePlatform.XliffConverter.Converter.ParseXliffString(translatedXliffText);

            Assert.IsTrue(translatedXliff.GetTargetSegments().Any());
            Assert.AreEqual(
                StringResource.BasicTranslation,
                translatedXliff.GetTargetSegments()[0].ToString());

            var token = ETSTranslatorHelper.GetAuthToken(basicAuthTranslationOptions, userCredentials);

            basicAuthTranslationOptions.ApiToken = token;

            translatedXliffText = ETSTranslatorHelper.GetTranslation(basicAuthTranslationOptions, engFraLP, xliffDocument);
            translatedXliff     = Sdl.Community.Toolkit.LanguagePlatform.XliffConverter.Converter.ParseXliffString(translatedXliffText);

            Assert.IsTrue(translatedXliff.GetTargetSegments().Any());
            Assert.AreEqual(
                StringResource.BasicTranslation,
                translatedXliff.GetTargetSegments()[0].ToString());
        }
コード例 #2
0
        public void ETSApi_FetchTranslation_InvalidTranslation()
        {
            XliffConverter.xliff xliffDocument = new XliffConverter.xliff(engFraLP.SourceCulture, engFraLP.TargetCulture);
            xliffDocument.AddSourceText(StringResource.BasicText);

            ETSTranslatorHelper.GetTranslation(apiKeyTranslationOptions, engInvLP, xliffDocument);
        }
コード例 #3
0
        public void ETSApi_FetchTranslationEmoji_ValidTranslation()
        {
            var xliffDocument = new Xliff(engFraLP.SourceCulture, engFraLP.TargetCulture, encodeUtf16: true);

            xliffDocument.AddSourceText(StringResource.BasicEmojiTest);

            var translatedXliffText = ETSTranslatorHelper.GetTranslation(apiKeyTranslationOptions, engFraLP, xliffDocument);
            var translatedXliff     = Sdl.Community.Toolkit.LanguagePlatform.XliffConverter.Converter.ParseXliffString(translatedXliffText);

            Assert.IsTrue(translatedXliff.GetTargetSegments().Any());
            Assert.AreEqual(StringResource.BasicEmojiTranslation, translatedXliff.GetTargetSegments()[0].ToString());
        }
コード例 #4
0
        public void ETSApi_FetchTranslationEmoji_ValidTranslation()
        {
            XliffConverter.xliff xliffDocument = new XliffConverter.xliff(engFraLP.SourceCulture, engFraLP.TargetCulture, encodeUTF16: true);

            xliffDocument.AddSourceText(StringResource.BasicEmojiTest);

            string translatedXliffText = ETSTranslatorHelper.GetTranslation(apiKeyTranslationOptions, engFraLP, xliffDocument);

            XliffConverter.xliff translatedXliff = XliffConverter.Converter.ParseXliffString(translatedXliffText);
            Assert.IsTrue(translatedXliff.GetTargetSegments().Any());
            Assert.AreEqual(
                StringResource.BasicEmojiTranslation,
                translatedXliff.GetTargetSegments()[0].ToString());
        }
コード例 #5
0
 public void ETSApi_GetBasicAuthToken_GetsToken()
 {
     try
     {
         var token = ETSTranslatorHelper.GetAuthToken(basicAuthTranslationOptions, userCredentials);
         if (token == null)
         {
             Assert.Fail("Expected token, but got null");
         }
     }
     catch (Exception ex)
     {
         Assert.Fail("Expected no exception, but got: " + ex.Message);
     }
 }
コード例 #6
0
        public void ETSApi_VerifyAPIKey_NoExceptionThrown()
        {
            var credentials = new GenericCredentials(null, null);

            credentials["API-Key"]   = apiKeyTranslationOptions.ApiToken;
            credentials["UseApiKey"] = "true";
            try
            {
                ETSTranslatorHelper.VerifyBasicAPIToken(apiKeyTranslationOptions, credentials);
            }
            catch (Exception ex)
            {
                Assert.Fail("Expected no exception, but got: " + ex.Message);
            }
        }
コード例 #7
0
        /// <summary>
        /// Creates a translated segment by calling upon the ETS API (via helper methods)
        /// </summary>
        /// <param name="sourceSegment"></param>
        /// <returns></returns>
        private Segment[] TranslateSegments(Segment[] sourceSegments)
        {
            var xliffDocument = CreateXliffFile(sourceSegments);

            var translatedXliffText = ETSTranslatorHelper.GetTranslation(
                provider.Options,
                languageDirection,
                xliffDocument);

            var translatedXliff = Converter.ParseXliffString(translatedXliffText);

            if (translatedXliff != null)
            {
                return(translatedXliff.GetTargetSegments());
            }
            return(new Segment[sourceSegments.Length]);
        }
コード例 #8
0
 public void ETSApi_FetchLPs_AtLeastFraEngReturned()
 {
     ETSLanguagePair[] lps = ETSTranslatorHelper.GetLanguagePairs(apiKeyTranslationOptions);
     if (!lps.Any())
     {
         Assert.Fail("Expected at least one LP returned");
     }
     // I realize not every ETS server will have german, but for sake of further tests, the host we choose to test with should.
     // Otherwise we'd have to code up an entire mock for the ETS API.
     if (!lps.Any(lp =>
                  lp.SourceLanguageId.Equals("eng", StringComparison.OrdinalIgnoreCase) &&
                  lp.TargetLanguageId.Equals("fra", StringComparison.OrdinalIgnoreCase)
                  ))
     {
         Assert.Fail("Expected EngFra as one of the LPs");
     }
 }
コード例 #9
0
        /// <summary>
        /// Creates a translated segment by calling upon the ETS API (via helper methods)
        /// </summary>
        /// <param name="sourceSegment"></param>
        /// <returns></returns>
        private Segment[] TranslateSegments(Segment[] sourceSegments)
        {
            Log.logger.Trace("");
            try
            {
                XliffConverter.xliff xliffDocument = CreateXliffFile(sourceSegments);

                string translatedXliffText = ETSTranslatorHelper.GetTranslation(
                    provider.Options,
                    languageDirection,
                    xliffDocument);

                XliffConverter.xliff translatedXliff = XliffConverter.Converter.ParseXliffString(translatedXliffText);
                return(translatedXliff.GetTargetSegments());
            }
            catch (Exception e)
            {
                Log.logger.Error(e, "Error in TranslateSegments");
                return(new Segment[sourceSegments.Length]);
            }
        }
コード例 #10
0
 /// <summary>
 /// Tests that we set the API version correctly depending on the host's api version
 /// </summary>
 public void ETSApi_SetETSApiVersion_v8()
 {
     apiKeyTranslationOptions.ApiVersion = APIVersion.Unknown;
     ETSTranslatorHelper.SetETSApiVersion(apiKeyTranslationOptions);
     Assert.AreEqual(APIVersion.v2, apiKeyTranslationOptions.ApiVersion);
 }