/// <summary> /// Initializes a new instance of the RemapTMXControl class. /// </summary> public RemapTMXControl() { this.InitializeComponent(); this.remapSettings = new RemapTMXSettings(); this.UpdateUI(this.remapSettings); }
/// <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)); } }