Пример #1
0
        public void ETSApi_FetchTranslationNoTags_ValidTranslation()
        {
            XliffConverter.xliff xliffDocument = new XliffConverter.xliff(engFraLP.SourceCulture, engFraLP.TargetCulture);
            xliffDocument.AddSourceText(StringResource.BasicText);

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

            XliffConverter.xliff translatedXliff = XliffConverter.Converter.ParseXliffString(translatedXliffText);

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

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

            basicAuthTranslationOptions.ApiToken = token;

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

            Assert.IsTrue(translatedXliff.GetTargetSegments().Any());
            Assert.AreEqual(
                StringResource.BasicTranslation,
                translatedXliff.GetTargetSegments()[0].ToString());
        }
Пример #2
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());
        }
Пример #3
0
        public void GetSegments_TaggedText_SameAsSource()
        {
            Segment[]            segments = SegmentParser.Parser.ParseFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TaggedFile.txt"));
            XliffConverter.xliff xliff    = new XliffConverter.xliff(
                CultureInfo.GetCultureInfo("en-us"), CultureInfo.GetCultureInfo("fr"));
            foreach (Segment segment in segments)
            {
                xliff.AddTranslation(segment, segment, "ETS");
            }

            Segment[] targetSegments = xliff.GetTargetSegments();
            for (int i = 0; i < segments.Length; i++)
            {
                Assert.AreEqual(segments[i].ToString(), targetSegments[i].ToString());
            }
        }
Пример #4
0
        public void GetSegments_NoTarget_NullTargetSegments()
        {
            Segment[] segments = SegmentParser.Parser.ParseFile(
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TaggedFile.txt"));
            XliffConverter.xliff xliff = new XliffConverter.xliff(
                CultureInfo.GetCultureInfo("en-us"), CultureInfo.GetCultureInfo("fr"));
            foreach (Segment segment in segments)
            {
                xliff.AddSourceSegment(segment);
            }

            Segment[] targetSegments = xliff.GetTargetSegments();
            foreach (Segment segment in targetSegments)
            {
                Assert.IsNull(segment);
            }
        }
Пример #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)
        {
            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]);
            }
        }