Exemplo n.º 1
0
        private List <FileData> GetFileDataList(Interfaces.IProject project, ProjectInfo studioProjectInfo, SdlxliffReader sdlxliffReader)
        {
            var fileDataList = new List <FileData>();

            foreach (var targetLanguage in project.TargetLanguages)
            {
                var targetFiles = project.ProjectFiles.Where(a =>
                                                             string.Compare(a.TargetLanguage, targetLanguage.CultureInfo.Name,
                                                                            StringComparison.CurrentCultureIgnoreCase) == 0);

                foreach (var projectFile in targetFiles)
                {
                    var inputPath            = Path.Combine(studioProjectInfo.LocalProjectFolder, projectFile.Location);
                    var data                 = sdlxliffReader.ReadFile(project.Id, projectFile.FileId, inputPath, projectFile.TargetLanguage);
                    var hasEmptyTranslations = ContainsEmptyTranslations(data);
                    fileDataList.Add(new FileData
                    {
                        Data = data,
                        HasEmptyTranslations = hasEmptyTranslations
                    });
                }
            }

            return(fileDataList);
        }
Exemplo n.º 2
0
        private Xliff GetBackTranslationXliffData(Interfaces.IProject project, ProjectFile projectFile, SdlxliffReader sdlxliffReader)
        {
            if (project != null && projectFile != null)
            {
                var backTranslationFilePath =
                    Path.Combine(project.Path, projectFile.Location);

                if (System.IO.File.Exists(backTranslationFilePath))
                {
                    return(sdlxliffReader.ReadFile(project.Id, projectFile.FileId,
                                                   backTranslationFilePath,
                                                   projectFile.TargetLanguage));
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        protected override void ConfigureConverter(ProjectFile projectFile, IMultiFileConverter multiFileConverter)
        {
            var languageName = projectFile.Language.CultureInfo.Name;

            var targetFile = _wizardContext.ProjectFiles.FirstOrDefault(a =>
                                                                        a.FileId == projectFile.Id.ToString() && a.TargetLanguage == languageName);

            if (targetFile != null)
            {
                if (!targetFile.Selected)
                {
                    return;
                }

                targetFile.Location = Path.Combine(targetFile.Project.Path, targetFile.Location.Trim('\\'));

                if (string.IsNullOrEmpty(_currentLanguage) || languageName != _currentLanguage)
                {
                    _logReport.AppendLine();
                    _logReport.AppendLine(string.Format(PluginResources.Label_Language, languageName));
                    _currentLanguage = languageName;
                }

                var sdlxliffReader = new SdlxliffReader(_segmentBuilder,
                                                        _exportSettings.ExportOptions,
                                                        GetAnalysisBands(Project as FileBasedProject));

                var xliffWriter = new XliffWriter(_exportSettings.ExportOptions.XliffSupport);

                var dateTimeStampToString = GetDateTimeStampToString(_exportSettings.DateTimeStamp);
                var workingFolder         = Path.Combine(_exportSettings.TransactionFolder, dateTimeStampToString);
                var languageFolder        = Path.Combine(workingFolder, languageName);

                var xliffFolder   = GetXliffFolder(languageFolder, targetFile);
                var xliffFilePath = Path.Combine(xliffFolder, targetFile.Name + ".xliff");

                _logReport.AppendLine(string.Format(PluginResources.label_SdlXliffFile, targetFile.Location));
                _logReport.AppendLine(string.Format(PluginResources.label_XliffFile, xliffFilePath));

                try
                {
                    var xliffData = sdlxliffReader.ReadFile(_projectInfo.Id.ToString(), targetFile.Location);
                    var exported  = xliffWriter.WriteFile(xliffData, xliffFilePath, _exportSettings.ExportOptions.IncludeTranslations);

                    if (exported)
                    {
                        targetFile.Date                        = new DateTime(_exportSettings.DateTimeStamp.Ticks, DateTimeKind.Utc);
                        targetFile.Action                      = Enumerators.Action.Export;
                        targetFile.Status                      = Enumerators.Status.Success;
                        targetFile.XliffFilePath               = xliffFilePath;
                        targetFile.ConfirmationStatistics      = sdlxliffReader.ConfirmationStatistics;
                        targetFile.TranslationOriginStatistics = sdlxliffReader.TranslationOriginStatistics;
                    }

                    var activityFile = new ProjectFileActivity
                    {
                        ProjectFileId               = targetFile.FileId,
                        ProjectFile                 = targetFile,
                        ActivityId                  = Guid.NewGuid().ToString(),
                        Action                      = Enumerators.Action.Export,
                        Status                      = exported ? Enumerators.Status.Success : Enumerators.Status.Error,
                        Date                        = targetFile.Date,
                        Name                        = Path.GetFileName(targetFile.XliffFilePath),
                        Path                        = Path.GetDirectoryName(targetFile.XliffFilePath),
                        ConfirmationStatistics      = targetFile.ConfirmationStatistics,
                        TranslationOriginStatistics = targetFile.TranslationOriginStatistics
                    };

                    targetFile.ProjectFileActivities.Add(activityFile);

                    if (!exported)
                    {
                        _isError = true;
                    }

                    _logReport.AppendLine(string.Format(PluginResources.Label_Success, exported));
                    _logReport.AppendLine();
                }
                catch (Exception ex)
                {
                    _logReport.AppendLine();
                    _logReport.AppendLine(string.Format(PluginResources.label_ExceptionMessage, ex.Message));

                    throw;
                }
            }
        }
Exemplo n.º 4
0
        public List <Report> CreateFinalReport(Interfaces.IProject project, FileBasedProject studioProject, List <ProjectFile> selectedFiles, out string workingPathOut)
        {
            var reports  = new List <Report>();
            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Indent             = false
            };
            var reportName = "Trados Transcreate Report";

            var studioProjectInfo     = studioProject.GetProjectInfo();
            var dateTimeStamp         = DateTime.UtcNow;
            var dataTimeStampToString = DateTimeStampToString(dateTimeStamp);
            var workflowPath          = GetPath(studioProjectInfo.LocalProjectFolder, "Workflow");
            var actionPath            = GetPath(workflowPath, "Report");
            var workingPath           = GetPath(actionPath, dataTimeStampToString);

            var exportOptions = new ExportOptions();

            exportOptions.IncludeBackTranslations = true;
            exportOptions.IncludeTranslations     = true;
            exportOptions.CopySourceToTarget      = false;

            var analysisBands = _projectAutomationService.GetAnalysisBands(studioProject);

            var progressSettings = new ProgressDialogSettings(ApplicationInstance.GetActiveForm(), true, true, false);
            var result           = ProgressDialog.ProgressDialog.Execute("Create Transcreate Reports", () =>
            {
                var sdlxliffReader = new SdlxliffReader(_segmentBuilder, exportOptions, analysisBands);
                decimal maximum    = project.ProjectFiles.Count;
                decimal current    = 0;
                foreach (var targetLanguage in project.TargetLanguages)
                {
                    var projectFiles = project.ProjectFiles.Where(a =>
                                                                  string.Compare(a.TargetLanguage, targetLanguage.CultureInfo.Name, StringComparison.CurrentCultureIgnoreCase) == 0).ToList();

                    var hasProjectFiles = HasProjectFiles(selectedFiles, projectFiles);
                    if (!hasProjectFiles)
                    {
                        current     += projectFiles.Count;
                        var progress = current / maximum * 100;

                        ProgressDialog.ProgressDialog.Current.Report((int)progress,
                                                                     string.Format("Language: {0}\r\nFile: {1}", targetLanguage.CultureInfo.DisplayName, projectFiles.FirstOrDefault().Name));

                        continue;
                    }

                    var workingLanguageFolder = GetPath(workingPath, targetLanguage.CultureInfo.Name);
                    foreach (var projectFile in projectFiles)
                    {
                        if (ProgressDialog.ProgressDialog.Current.CheckCancellationPending())
                        {
                            ProgressDialog.ProgressDialog.Current.ThrowIfCancellationPending();
                        }

                        current++;
                        var progress = current / maximum * 100;
                        ProgressDialog.ProgressDialog.Current.Report((int)progress, string.Format("Language: {0}\r\nFile: {1}", targetLanguage.CultureInfo.DisplayName, projectFile.Name));

                        if (selectedFiles != null && !selectedFiles.Exists(a => a.FileId == projectFile.FileId))
                        {
                            continue;
                        }

                        var projectFilePath = Path.Combine(project.Path, projectFile.Location);
                        var xliffData       = sdlxliffReader.ReadFile(project.Id, projectFile.FileId, projectFilePath,
                                                                      targetLanguage.CultureInfo.Name);

                        var backTranslationProject   = GetBackTranslationProject(project, targetLanguage.CultureInfo.Name);
                        var backTranslationFile      = GetBackTranslationProjectFile(backTranslationProject, projectFile);
                        var xliffDataBackTranslation = GetBackTranslationXliffData(backTranslationProject, backTranslationFile, sdlxliffReader);

                        var fileName   = projectFile.Name.Substring(0, projectFile.Name.LastIndexOf(".", StringComparison.Ordinal));
                        var reportFile = Path.Combine(workingLanguageFolder, fileName + ".xml");

                        using (var writer = XmlWriter.Create(reportFile, settings))
                        {
                            writer.WriteStartElement("task");
                            writer.WriteAttributeString("name", reportName);
                            writer.WriteAttributeString("created", dataTimeStampToString);

                            writer.WriteStartElement("taskInfo");
                            writer.WriteAttributeString("action", "Trados Transcreate Report");
                            writer.WriteAttributeString("file", projectFile.Path + projectFile.Name);
                            writer.WriteAttributeString("taskId", Guid.NewGuid().ToString());
                            writer.WriteAttributeString("runAt", GetDisplayDateTime(dateTimeStamp));


                            WriteReportProject(writer, "project", project);
                            WriteReportProject(writer, "backProject", backTranslationProject);

                            WriteReportLanguage(writer, "source", project.SourceLanguage.CultureInfo.Name);
                            WriteReportLanguage(writer, "target", targetLanguage.CultureInfo.Name);

                            WriteReportCustomer(writer, project);

                            WriteReportTranslationProviders(writer, studioProject);

                            writer.WriteEndElement();                             //taskInfo


                            writer.WriteStartElement("translations");
                            foreach (var dataFile in xliffData.Files)
                            {
                                writer.WriteStartElement("version");
                                writer.WriteAttributeString("type", dataFile.Original);

                                var backTranslationDataFile =
                                    xliffDataBackTranslation?.Files.FirstOrDefault(a => a.Original == dataFile.Original);

                                writer.WriteStartElement("segments");
                                foreach (var transUnit in dataFile.Body.TransUnits)
                                {
                                    var textFunction = transUnit.Contexts.FirstOrDefault(
                                        a => string.Compare(a.DisplayName, "Text Function", StringComparison.CurrentCultureIgnoreCase) == 0);

                                    foreach (var segmentPair in transUnit.SegmentPairs)
                                    {
                                        writer.WriteStartElement("segment");

                                        var backTranslationSegmentPair = GetBackTranslationSegmentPair(backTranslationDataFile, segmentPair);

                                        writer.WriteAttributeString("id", segmentPair.Id);
                                        writer.WriteAttributeString("textFunction", textFunction?.Description ?? string.Empty);

                                        writer.WriteStartElement("source");
                                        writer.WriteString(segmentPair.Source.ToString());
                                        writer.WriteEndElement();                                         //source

                                        writer.WriteStartElement("target");
                                        writer.WriteString(segmentPair.Target.ToString());
                                        writer.WriteEndElement();                                         //source

                                        writer.WriteStartElement("back");
                                        writer.WriteString(backTranslationSegmentPair?.Target?.ToString() ?? string.Empty);
                                        writer.WriteEndElement();                                         //backTranslation

                                        writer.WriteStartElement("comments");
                                        var comments = GetSegmentComments(segmentPair.Target, xliffData.DocInfo);
                                        if (comments != null)
                                        {
                                            foreach (var comment in comments)
                                            {
                                                writer.WriteStartElement("comment");
                                                writer.WriteAttributeString("version", comment.Version);
                                                writer.WriteAttributeString("author", comment.Author);
                                                writer.WriteAttributeString("severity", comment.Severity.ToString());
                                                writer.WriteAttributeString("date", GetDisplayDateTime(comment.Date));
                                                writer.WriteString(comment.Text ?? string.Empty);
                                                writer.WriteEndElement();                                                 //comment
                                            }
                                        }

                                        writer.WriteEndElement();                                         //comments

                                        writer.WriteEndElement();                                         //segment
                                    }
                                }
                                writer.WriteEndElement();                         //segments

                                writer.WriteEndElement();                         //version
                            }
                            writer.WriteEndElement();                             //translations
                        }

                        // transform the file against an xslt
                        var templatePath   = GetReportTemplatePath("TranscreateFinalReport.xsl");
                        var reportFilePath = CreateHtmlReportFile(reportFile, templatePath);


                        var report = new Report
                        {
                            Name        = fileName,
                            Date        = dateTimeStamp,
                            Description = "Transcreate Report",
                            Group       = "Transcreate Report",
                            Language    = targetLanguage.CultureInfo.Name,
                            Path        = reportFilePath
                        };
                        reports.Add(report);
                    }
                }
            }, progressSettings);

            workingPathOut = workingPath;

            if (result.Cancelled)
            {
                System.Windows.Forms.MessageBox.Show("Process cancelled by user.", PluginResources.Plugin_Name);
                return(new List <Report>());
            }

            return(reports);
        }
Exemplo n.º 5
0
        private Dictionary <string, List <string> > GetParagraphMap(SdlxliffReader sdlxliffReader, string projectId, string fileId, string path, string targetLanguage)
        {
            var xliffData = sdlxliffReader.ReadFile(projectId, fileId, path, targetLanguage);

            return(GetParagraphMap(xliffData));
        }