Пример #1
0
        public async Task <string> Export()
        {
            var exporter = new TranslationMemoryExporter(_tm.LanguageDirection);

            var exportName = string.Format(
                CultureInfo.CurrentCulture,
                "{0}_{1}_{2}.tmx",
                _tm.Name,
                _tm.LanguageDirection.SourceLanguage,
                _tm.LanguageDirection.TargetLanguage);

            var exportFullPath = Path.Combine(Path.GetDirectoryName(_tm.FilePath), exportName);

            if (File.Exists(exportFullPath))
            {
                File.Delete(exportFullPath);
            }

            var t = new Task(() => exporter.Export(exportFullPath, true));

            t.Start();
            await t;

            return(exportFullPath);
        }
        public void ExportTMXFile(string tmPath, string exportFilePath)
        {
            FileBasedTranslationMemory tm       = new FileBasedTranslationMemory(tmPath);
            TranslationMemoryExporter  exporter = new TranslationMemoryExporter(tm.LanguageDirection);

            // Chunk size - It has a max of 200, changing this up would make the program run faster at the
            // Expense of memory (RAM) usage
            exporter.ChunkSize = 50;

            exporter.Export(exportFilePath, true);
        }
Пример #3
0
        /// <summary>
        /// Export specified TM into the tmx file
        /// </summary>
        /// <param name="tmPath"></param>
        /// <param name="exportFilePath"></param>
        public void ExportTMXFile(string tmPath, string exportFilePath)
        {
            FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath);

            TranslationMemoryExporter exporter = new TranslationMemoryExporter(tm.LanguageDirection);

            exporter.FilterExpression = GetExportFilter();

            exporter.BatchExported += new EventHandler <BatchExportedEventArgs>(exporter_BatchExported);

            exporter.ChunkSize = 1; //sets the import size after which the BatchExported event is launched

            exporter.Export(exportFilePath, true);
        }
Пример #4
0
        public void RunFilteredExport(string tmPath, string exportFilePath)
        {
            #region "OpenForFilter"
            FileBasedTranslationMemory tm       = new FileBasedTranslationMemory(tmPath);
            TranslationMemoryExporter  exporter = new TranslationMemoryExporter(tm.LanguageDirection);
            #endregion

            #region "FilterDefinition"
            exporter.FilterExpression = GetFilterSimple();
            #endregion

            #region "DoFilteredExport"
            exporter.BatchExported += new EventHandler <BatchExportedEventArgs>(Exporter_BatchExported);
            exporter.Export(exportFilePath, true);
            #endregion
        }
Пример #5
0
        public void ExportTMXFile(string tmPath, string exportFilePath)
        {
            #region "open"
            FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath);

            TranslationMemoryExporter exporter = new TranslationMemoryExporter(tm.LanguageDirection);
            #endregion

            #region "chunk"
            exporter.ChunkSize = 20;

            #endregion

            #region "FireEvent"
            exporter.BatchExported += new EventHandler <BatchExportedEventArgs>(Exporter_BatchExported);
            #endregion

            #region "execute"
            exporter.Export(exportFilePath, true);
            #endregion
        }
Пример #6
0
        public async Task <string> Export()
        {
            TotalExported = 0;

            var exporter = new TranslationMemoryExporter(_tm.LanguageDirection);

            TotalUnits = exporter.TranslationMemoryLanguageDirection.GetTranslationUnitCount();

            exporter.BatchExported += exporter_BatchExported;
            var exportName = string.Format(
                CultureInfo.CurrentCulture,
                "{0}_{1}_{2}.tmx",
                _tm.Name,
                _tm.LanguageDirection.SourceLanguage,
                _tm.LanguageDirection.TargetLanguage);

            var exportFullPath = Path.Combine(Path.GetDirectoryName(_tm.FilePath), exportName);

            if (File.Exists(exportFullPath))
            {
                File.Delete(exportFullPath);
            }


            var t = new Task(() => exporter.Export(exportFullPath, true));

            t.ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    throw new Exception(ProcessorUtil.ExceptionToMsg(task.Exception));
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());

            t.Start();
            await t;

            return(exportFullPath);
        }
        /// <summary>
        /// This function performs the actual export operation.
        /// *.sdltm files are exported to *.tmx format.
        /// </summary>
        /// <param name="translationMemoryPath">FileBasedTranslationMemory to export into.</param>
        public void Export(string translationMemoryPath)
        {
            this.exportProgress = 0;
            FileBasedTranslationMemory tm       = new FileBasedTranslationMemory(translationMemoryPath);
            TranslationMemoryExporter  exporter = new TranslationMemoryExporter(tm.LanguageDirection);

            // set event handler
            exporter.BatchExported += new EventHandler <BatchExportedEventArgs>(this.Exporter_BatchExported);

            // The *.tmx export files have the same name as the original
            // *.sdltm files, including the language direction retrieved
            // from the file TM, e.g. "en-US_de-DE".
            string exportString = string.Format(
                CultureInfo.CurrentCulture,
                "{0}_{1}_{2}.tmx",
                translationMemoryPath,
                tm.LanguageDirection.SourceLanguage,
                tm.LanguageDirection.TargetLanguage);

            exporter.Export(exportString, true);

            Console.Write("Translation Units exported: {0} \n", this.exportProgress);
        }
Пример #8
0
        protected override void ExecuteImpl()
        {
            TranslationMemoryExporter exporter = new TranslationMemoryExporter(_translationMemory.LanguageDirection);
            int tuCount = _translationMemory.LanguageDirection.GetTranslationUnitCount();
            exporter.BatchExported += (sender, e) =>
            {
                StatusMessage = String.Format("TUs: {0}/{1}", e.TotalProcessed, tuCount);
                ReportProgress((int)((100.0 * e.TotalExported) / tuCount));
            };
            exporter.TmxExportFormat = Sdl.LanguagePlatform.TranslationMemory.TranslationUnitFormat.SDLTradosStudio2009;
            
            exporter.Export(_exportTmxFile.FilePath, true);

            _exportTmxFile.DetectInfo = new DetectInfo
            {
                DetectedVersion = DetectInfo.Versions.Studio,
                SourceLanguage = new Language(_translationMemory.LanguageDirection.SourceLanguage),
                TargetLanguage = new Language(_translationMemory.LanguageDirection.TargetLanguage),
                OriginalSourceLanguage = _translationMemory.LanguageDirection.SourceLanguage.Name,
                OriginalTargetLanguage = _translationMemory.LanguageDirection.TargetLanguage.Name,
                TuCount = tuCount
            };
        }
Пример #9
0
        protected override void ExecuteImpl()
        {
            TranslationMemoryExporter exporter = new TranslationMemoryExporter(_translationMemory.LanguageDirection);
            int tuCount = _translationMemory.LanguageDirection.GetTranslationUnitCount();

            exporter.BatchExported += (sender, e) =>
            {
                StatusMessage = String.Format("TUs: {0}/{1}", e.TotalProcessed, tuCount);
                ReportProgress((int)((100.0 * e.TotalExported) / tuCount));
            };
            exporter.TmxExportFormat = Sdl.LanguagePlatform.TranslationMemory.TranslationUnitFormat.SDLTradosStudio2009;

            exporter.Export(_exportTmxFile.FilePath, true);

            _exportTmxFile.DetectInfo = new DetectInfo
            {
                DetectedVersion        = DetectInfo.Versions.Studio,
                SourceLanguage         = new Language(_translationMemory.LanguageDirection.SourceLanguage),
                TargetLanguage         = new Language(_translationMemory.LanguageDirection.TargetLanguage),
                OriginalSourceLanguage = _translationMemory.LanguageDirection.SourceLanguage.Name,
                OriginalTargetLanguage = _translationMemory.LanguageDirection.TargetLanguage.Name,
                TuCount = tuCount
            };
        }
Пример #10
0
        /// <summary>
        /// Performs task.
        /// </summary>
        /// <param name="fileName">Physical path to file.</param>
        public void Execute(string fileName)
        {
            try
            {
                FileBasedTranslationMemory tm       = new FileBasedTranslationMemory(fileName);
                RemapTMXSettings           settings = (RemapTMXSettings)this.Control.Options;

                // check for unsupported languages
                string culture             = string.Empty;
                bool   containsUnsupported = false;

                if (this.notSupportedCultures.Contains(tm.LanguageDirection.SourceLanguage.Name))
                {
                    culture             = tm.LanguageDirection.SourceLanguage.EnglishName;
                    containsUnsupported = true;
                }

                if (this.notSupportedCultures.Contains(tm.LanguageDirection.TargetLanguage.Name))
                {
                    culture             = tm.LanguageDirection.TargetLanguage.EnglishName;
                    containsUnsupported = true;
                }

                if (containsUnsupported)
                {
                    var result = MessageBox.Show(
                        string.Format(
                            Properties.Resources.NotSupportedCulture,
                            culture),
                        string.Empty,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Information,
                        MessageBoxDefaultButton.Button2);
                    if (result == DialogResult.No)
                    {
                        this.OnProgressChanged(100, string.Empty);
                        this.OnLogAddedChanged(string.Format(Properties.Resources.SkipTM, fileName));
                        return;
                    }
                }

                this.OnProgressChanged(0, string.Format(Properties.Resources.TMExportStarted, fileName));

                // Export into TMX
                TranslationMemoryExporter exporter = new TranslationMemoryExporter()
                {
                    ChunkSize = Sdl.LanguagePlatform.TranslationMemoryApi.TranslationMemoryExporter.DefaultTranslationUnitChunkSize,
                    TranslationMemoryLanguageDirection = tm.LanguageDirection
                };

                exporter.BatchExported += (object obj, BatchExportedEventArgs args) =>
                {
                    StringBuilder info = new StringBuilder();

                    info.AppendLine(string.Format(Properties.Resources.TotalTUProcessed, args.TotalProcessed));
                    info.AppendLine(string.Format(Properties.Resources.TotalTUExported, args.TotalExported));

                    this.OnLogAddedChanged(info.ToString());
                    args.Cancel = false;
                };

                string targetTMXFile = string.Format(
                    "{0}{1}{2}.tmx",
                    settings.TargetFolder,
                    Path.DirectorySeparatorChar,
                    Path.GetFileNameWithoutExtension(fileName));
                exporter.Export(targetTMXFile, true);

                // convert TMX into required format

                var    flavour = TranslationUnitFormat.TradosTranslatorsWorkbench;
                string targetTMXFlavouredFile = string.Empty;
                if (settings.SaveIntoTargetFolder)
                {
                    targetTMXFlavouredFile = string.Format(
                        "{0}{1}{2}_Trados2019.tmx",
                        Path.GetDirectoryName(fileName),
                        Path.DirectorySeparatorChar,
                        Path.GetFileNameWithoutExtension(fileName));
                }
                else
                {
                    targetTMXFlavouredFile = string.Format(
                        "{0}{1}{2}_Trados2019.tmx",
                        settings.TargetFolder,
                        Path.DirectorySeparatorChar,
                        Path.GetFileNameWithoutExtension(fileName));
                }

                this.Convert(targetTMXFile, targetTMXFlavouredFile, flavour);
                this.OnProgressChanged(0, string.Empty);
                this.OnLogAddedChanged(string.Format(Properties.Resources.TMXFlavouredConverted, targetTMXFile));

                File.Delete(targetTMXFile);

                this.OnProgressChanged(100, string.Empty);
                this.OnLogAddedChanged(string.Format(Properties.Resources.TMExportFinished, fileName));
            }
            catch (Exception ex)
            {
                this.OnProgressChanged(0, string.Empty);
                this.OnLogAddedChanged(string.Format(Properties.Resources.RemapException, ex.Message));
            }
        }
Пример #11
0
 /// <summary>
 /// creates new exporter
 /// </summary>
 public Exporter()
 {
     _exporter = new TranslationMemoryExporter();
 }