コード例 #1
0
        public void Execute()
        {
            var tusNode = from el in ReadFromTmxFile(_inputFile.FilePath) select el;

            var outputWriter = new OutputWriter(_outputFile.FilePath);

            outputWriter.InitializeStudioTmx(_inputFile.DetectInfo.SourceLanguage.IsoAbbreviation);

            int tuIndex = 0;
            int tuCount = 0;

            foreach (var tu in tusNode)
            {
                var format = from propElement in tu.Elements("prop")
                             where propElement.Attribute("type").Value == "x-OriginalFormat" && propElement.Value == "TradosTranslatorsWorkbench"
                             select propElement.Parent;

                if (!format.Any())
                {
                    outputWriter.Write(tu.ToString());
                    tuCount++;
                }
                else
                {
                    TusStripped++;
                }

                TusRead++;
                ReportProgress((int)(100.0 * tuIndex / _inputFile.GetDetectInfo().TuCount));
            }

            outputWriter.Complete();

            // output file has same properties as input file
            _outputFile.DetectInfo         = _inputFile.GetDetectInfo().Clone();
            _outputFile.DetectInfo.TuCount = tuCount;
            ReportProgress(100);
        }
コード例 #2
0
ファイル: Stripper.cs プロジェクト: desautel/Sdl-Community
        public void Execute()
        {
            var tusNode = from el in ReadFromTmxFile(_inputFile.FilePath) select el;

            var outputWriter = new OutputWriter(_outputFile.FilePath);
            outputWriter.InitializeStudioTmx(_inputFile.DetectInfo.SourceLanguage.IsoAbbreviation);

            int tuIndex = 0;
            int tuCount = 0;
            foreach (var tu in tusNode)
            {
                var format = from propElement in tu.Elements("prop")
                             where propElement.Attribute("type").Value == "x-OriginalFormat" && propElement.Value == "TradosTranslatorsWorkbench"
                             select propElement.Parent;

                if (!format.Any())
                {
                    outputWriter.Write(tu.ToString());
                    tuCount++;
                }
                else
                {
                    TusStripped++;
                }

                TusRead++;
                ReportProgress((int)(100.0 * tuIndex / _inputFile.GetDetectInfo().TuCount));
            }

            outputWriter.Complete();

            // output file has same properties as input file
            _outputFile.DetectInfo = _inputFile.GetDetectInfo().Clone();
            _outputFile.DetectInfo.TuCount = tuCount;
            ReportProgress(100);
        }
コード例 #3
0
ファイル: Cleaner.cs プロジェクト: desautel/Sdl-Community
        public void Execute()
        {
            var tusNode = from el in ReadFromTmxFile(_inputFile.FilePath) select el;

            var outputWriter = new OutputWriter(_outputFile.FilePath);
            outputWriter.InitializeWorkbenchTmx(_inputFile.DetectInfo.OriginalSourceLanguage);


            int tuIndex = 0;
            foreach (var tu in tusNode)
            {
                var source = tu.Elements("tuv").First().Element("seg");
                var target = tu.Elements("tuv").Last().Element("seg");

                if (source == null || target == null)
                {
                    continue;
                }

                int tagsUpdated = 0;
                int tagsRemoved = 0;
                    
                if ((source.Elements("bpt").Any() || target.Elements("bpt").Any()))
                {
                    StripFontTags(source, ref tagsUpdated, ref tagsRemoved);
                    StripFontTags(target, ref tagsUpdated, ref tagsRemoved);
                }

                if (_settings.RemoveOrphan && !source.Elements("bpt").Any())
                {
                    tagsRemoved += target.Elements("bpt").Count();
                    tagsRemoved += target.Elements("ept").Count();
                    target.Elements("bpt").Remove();
                    target.Elements("ept").Remove();
                }

                if(_settings.ReplaceSoftHyphen)
                {
                    if (source.Elements("ph").Any())
                    {
                        ReplaceSoftHyphen(source, ref tagsUpdated);
                    }

                    if (target.Elements("ph").Any())
                    {
                        ReplaceSoftHyphen(target, ref tagsUpdated);
                    }
                }

                // update statistics
                tuIndex++;
                TusRead++;
                if (tagsUpdated > 0 || tagsRemoved > 0)
                {
                    TusCleaned++;
                    TagsUpdated += tagsUpdated;
                    TagsRemoved += tagsRemoved;
                }

                // write TU
                outputWriter.Write(tu.ToString());
                                
                ReportProgress((int)(100.0 * tuIndex / _inputFile.GetDetectInfo().TuCount));

                if (_remainingTuProcessingQuota != null)
                {
                    _remainingTuProcessingQuota = _remainingTuProcessingQuota.Value - 1;

                    if (_remainingTuProcessingQuota.Value == 0)
                    {
                        break;
                    }
                }
            }

            outputWriter.Complete();
            
            // output file has same properties as input file
            _outputFile.DetectInfo = _inputFile.GetDetectInfo().Clone();
            _outputFile.DetectInfo.TuCount = TusRead;
                        
            ReportProgress(100);
        }
コード例 #4
0
        public void Execute()
        {
            var tusNode = from el in ReadFromTmxFile(_inputFile.FilePath) select el;

            var outputWriter = new OutputWriter(_outputFile.FilePath);

            outputWriter.InitializeWorkbenchTmx(_inputFile.DetectInfo.OriginalSourceLanguage);


            int tuIndex = 0;

            foreach (var tu in tusNode)
            {
                var source = tu.Elements("tuv").First().Element("seg");
                var target = tu.Elements("tuv").Last().Element("seg");

                if (source == null || target == null)
                {
                    continue;
                }

                int tagsUpdated = 0;
                int tagsRemoved = 0;

                if ((source.Elements("bpt").Any() || target.Elements("bpt").Any()))
                {
                    StripFontTags(source, ref tagsUpdated, ref tagsRemoved);
                    StripFontTags(target, ref tagsUpdated, ref tagsRemoved);
                }

                if (_settings.RemoveOrphan && !source.Elements("bpt").Any())
                {
                    tagsRemoved += target.Elements("bpt").Count();
                    tagsRemoved += target.Elements("ept").Count();
                    target.Elements("bpt").Remove();
                    target.Elements("ept").Remove();
                }

                if (_settings.ReplaceSoftHyphen)
                {
                    if (source.Elements("ph").Any())
                    {
                        ReplaceSoftHyphen(source, ref tagsUpdated);
                    }

                    if (target.Elements("ph").Any())
                    {
                        ReplaceSoftHyphen(target, ref tagsUpdated);
                    }
                }

                // update statistics
                tuIndex++;
                TusRead++;
                if (tagsUpdated > 0 || tagsRemoved > 0)
                {
                    TusCleaned++;
                    TagsUpdated += tagsUpdated;
                    TagsRemoved += tagsRemoved;
                }

                // write TU
                outputWriter.Write(tu.ToString());

                ReportProgress((int)(100.0 * tuIndex / _inputFile.GetDetectInfo().TuCount));

                if (_remainingTuProcessingQuota != null)
                {
                    _remainingTuProcessingQuota = _remainingTuProcessingQuota.Value - 1;

                    if (_remainingTuProcessingQuota.Value == 0)
                    {
                        break;
                    }
                }
            }

            outputWriter.Complete();

            // output file has same properties as input file
            _outputFile.DetectInfo         = _inputFile.GetDetectInfo().Clone();
            _outputFile.DetectInfo.TuCount = TusRead;

            ReportProgress(100);
        }