Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 5
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]);
        }
Ejemplo n.º 6
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]);
            }
        }