public void Reindex(List<TranslationMemoryInfo> tms, BackgroundWorker bw) { //remove possible duplicates based on the URI var distinctTms = tms.GroupBy(k => k.Uri) .Where(g => g.Any()) .Select(g => g.FirstOrDefault()) .ToList(); Parallel.ForEach(distinctTms, tm => { _reindexStatus.AppendLine(string.Format("Start reindex {0} translation memory", tm.Name)); bw.ReportProgress(0, _reindexStatus.ToString()); var fileBasedTm = new FileBasedTranslationMemory(tm.FilePath); if ((fileBasedTm.Recognizers & BuiltinRecognizers.RecognizeAlphaNumeric) == 0) { fileBasedTm.Recognizers |= BuiltinRecognizers.RecognizeAlphaNumeric; } var languageDirection = fileBasedTm.LanguageDirection; var iterator = new LanguagePlatform.TranslationMemory.RegularIterator(100); while (languageDirection.ReindexTranslationUnits(ref iterator)) { bw.ReportProgress(0, _reindexStatus.ToString()); } fileBasedTm.RecomputeFuzzyIndexStatistics(); fileBasedTm.Save(); _reindexStatus.AppendLine(string.Format("Finish reindex {0} translation memory", tm.Name)); bw.ReportProgress(0, _reindexStatus.ToString()); }); }
/// <summary> /// Change target segment content of existing TU /// </summary> /// <param name="tmPath"></param> /// <param name="searchedText"></param> /// <param name="newTarget"></param> public void AdaptTU(string tmPath, string searchedText, string newTarget) { FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath); SearchResults results = tm.LanguageDirection.SearchText(GetSearchSettings(), searchedText); foreach (SearchResult item in results) { if (item.ScoringResult.Match == 100) { item.MemoryTranslationUnit.TargetSegment.Clear();//remove existing target segment content item.MemoryTranslationUnit.TargetSegment.Add(newTarget); item.MemoryTranslationUnit.SystemFields.UseCount++; MultiplePicklistFieldValue picklistValue = new MultiplePicklistFieldValue("Sample field"); picklistValue.Add("yes"); item.MemoryTranslationUnit.FieldValues.Add(picklistValue); MultipleStringFieldValue stringValue = new MultipleStringFieldValue("Sample text field"); stringValue.Add("new item"); stringValue.Add("new project"); item.MemoryTranslationUnit.FieldValues.Add(stringValue); WriteResult("TU found and changed."); break; } } }
public TransitTmImporter(CultureInfo sourceCulture, CultureInfo targetCulture, bool createTm, IFileTypeManager fileTypeManager, string studioTranslationMemory) { _sourceCulture = sourceCulture; _targetCulture = targetCulture; _createTm = createTm; _fileTypeManager = fileTypeManager; if (_createTm) { _fileBasedTM = new FileBasedTranslationMemory(studioTranslationMemory, string.Empty, _sourceCulture, _targetCulture, FuzzyIndexes.SourceWordBased | FuzzyIndexes.SourceCharacterBased | FuzzyIndexes.TargetCharacterBased | FuzzyIndexes.TargetWordBased, BuiltinRecognizers.RecognizeAll, TokenizerFlags.DefaultFlags, WordCountFlags.BreakOnTag | WordCountFlags.BreakOnDash | WordCountFlags.BreakOnApostrophe); } else { _fileBasedTM = new FileBasedTranslationMemory(studioTranslationMemory); } }
public TmExporter(FileBasedTranslationMemory tm, int totalUnits) { _tm = tm; TotalExported = 0; TotalProcessed = 0; TotalUnits = totalUnits; }
private void CreateStudioTranslationMemory(string tmPath, string description, int penalty, LanguagePair languagePair) { FileBasedTranslationMemory fileBasedTm; if (languagePair != null) { fileBasedTm = new FileBasedTranslationMemory( tmPath, description, languagePair.SourceLanguage, languagePair.TargetLanguage, FuzzyIndexes.SourceCharacterBased | FuzzyIndexes.SourceWordBased | FuzzyIndexes.TargetCharacterBased | FuzzyIndexes.TargetWordBased, BuiltinRecognizers.RecognizeAll, TokenizerFlags.DefaultFlags, WordCountFlags.BreakOnTag | WordCountFlags.BreakOnDash | WordCountFlags.BreakOnApostrophe); } else { fileBasedTm = new FileBasedTranslationMemory(tmPath); } fileBasedTm.Save(); if (!StudioTranslationMemories.ContainsKey(fileBasedTm)) { StudioTranslationMemories.Add(fileBasedTm, penalty); } }
/// <summary> /// Create a new file based TM on specified path /// </summary> /// <param name="tmPath"></param> public void CreateNewFileBasedTM(string tmPath) { //create a new TM FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath, "A sample created as example of using TM API.", CultureInfo.GetCultureInfo("en-US"), CultureInfo.GetCultureInfo("de-DE"), GetFuzzyIndexes(), GetRecognizers(), TokenizerFlags.AllFlags, WordCountFlags.AllFlags); WriteResult("TM " + tmPath + " created.\r\n"); //start changing the default properties tm.Copyright = "SDK Sample"; tm.ExpirationDate = DateTime.Now.AddDays(2); //will expire in 2 days AdaptFields(tm.FieldDefinitions); AdaptLanguageResourceBundles(tm.LanguageResourceBundles); //save all changes tm.Save(); }
public TransitTmImporter(CultureInfo sourceCulture, CultureInfo targetCulture, bool createTm, IFileTypeManager fileTypeManager, string studioTranslationMemory) { _sourceCulture = sourceCulture; _targetCulture = targetCulture; _createTm = createTm; _fileTypeManager = fileTypeManager; if (_createTm) { _fileBasedTM = new FileBasedTranslationMemory( studioTranslationMemory, string.Empty, _sourceCulture, _targetCulture, GetFuzzyIndexes(), GetRecognizers(), TokenizerFlags.DefaultFlags, GetWordCountFlags()); } else { _fileBasedTM = new FileBasedTranslationMemory(studioTranslationMemory); } }
/// <summary> /// creates new TM /// </summary> /// <param name="TM">TM to get settings (desc, source lang, target lang) from</param> /// <param name="isIndexRevert">create TM with reverted index</param> public void CreateNewTM(FileBasedTranslationMemory TM, bool isIndexRevert) { FilePath = FileHelper.ChangeFileName(FilePath, @"{0}\{1}_{2}.sdltm"); if (isIndexRevert) { NewTM = new FileBasedTranslationMemory(FilePath, (TM.Description == null ? "" : TM.Description), TM.LanguageDirection.TargetLanguage, TM.LanguageDirection.SourceLanguage, TM.FuzzyIndexes, TM.Recognizers, TM.TokenizerFlags, TM.WordCountFlags); } else { NewTM = new FileBasedTranslationMemory(FilePath, (TM.Description == null ? "" : TM.Description), TM.LanguageDirection.SourceLanguage, TM.LanguageDirection.TargetLanguage, TM.FuzzyIndexes, TM.Recognizers, TM.TokenizerFlags, TM.WordCountFlags); } TUsCount = 0; // manage settings, get settings from old TM CopySettings(TM); NewTM.Save(); }
public void AddTuExtended(string tmPath) { #region "OpenExtended" FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath); TranslationUnit tu = new TranslationUnit(); #endregion #region "SegmentsExtended" tu.SourceSegment = new Segment(tm.LanguageDirection.SourceLanguage); tu.TargetSegment = new Segment(tm.LanguageDirection.TargetLanguage); #endregion #region "elements" SegmentElement srcElement = this.GetSourceElement(); SegmentElement trgElement = this.GetTargetElement(); tu.SourceSegment.Add(srcElement); tu.TargetSegment.Add(trgElement); #endregion #region "AddTuExtended" tm.LanguageDirection.AddTranslationUnit(tu, this.GetImportSettings()); tm.Save(); MessageBox.Show("TU has been added successfully."); #endregion }
public void SetProcessingVariables(string inputTmFullPath, string outputTmFullPath, bool quickAlign = false) { _filebasedTmIn = null; _fileBasedTmOut = null; if (string.IsNullOrEmpty(inputTmFullPath)) { throw new Exception(Resources.FragmentAlignment_InputTmPathCannotBeNull); } if (string.IsNullOrEmpty(outputTmFullPath)) { throw new Exception(Resources.FragmentAlignment_OutputTmPathCannotBeNull); } InputTmFullPathFullPath = inputTmFullPath; OutputTmFullPathFullPath = outputTmFullPath; QuickAlign = quickAlign; // TODO // this will return the total number of translation units for the all language directions // in the TM; // refactor: should reference the language direction being processed! // the reason that this is being processed here as it can be a costly operation and only // needs to occur once. TotalUnits = FileBasedTmIn.GetTranslationUnitCount(); }
/// <summary> /// The constructor creates the translation memory /// Adds the project's source and target languages to the TM /// Creates the core directory structure (if not present) /// </summary> /// <param name="settings"></param> /// <param name="projectFile"></param> public FileReader(TMBatchTaskSettings settings, ProjectFile projectFile, ref BatchTaskLogger logger) { // Note: This is not currently in use. Marked for potential deletion //this._taskSettings = settings; //this._inputFilePath = projectFile.LocalFilePath; this.referenceNumbers = new List <string>(); this.tmDetails = new TMDetails(); this.logger = logger; // Setting up language abbreviations in the TM details class tmDetails.SourceLanguage = projectFile.SourceFile.Language.CultureInfo; tmDetails.TargetLanguage = projectFile.Language.CultureInfo; // Creating a new folder structure for the translation memory string dirPath = Path.GetDirectoryName(projectFile.LocalFilePath); string fileName = Path.GetFileNameWithoutExtension(projectFile.LocalFilePath); DirectoryInfo sdltmDir = Directory.CreateDirectory($"{dirPath}\\TranslationMemories\\{fileName}"); DirectoryInfo tmxDirectory = Directory.CreateDirectory($"{sdltmDir.FullName}\\Exports"); tmxDir = $"{tmxDirectory.FullName}\\{fileName}.tmx"; // Creating a translation memory TMCreator objCreate = new TMCreator(); tm = objCreate.CreateFileBasedTM($"{sdltmDir.FullName}\\{Utility.RandomString(10)}.sdltm", projectFile.SourceFile.Language.CultureInfo, projectFile.Language.CultureInfo); }
public void GetInfo(string tmPath) { #region "open" FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath); SearchResults results = tm.LanguageDirection.SearchText(GetSearchSettings(), "A dialog box will open."); #endregion #region "output" string tuInfo = string.Empty; foreach (SearchResult item in results) { if (item.ScoringResult.Match == 100) { TranslationUnit tu = item.MemoryTranslationUnit; SystemFields sysFields = tu.SystemFields; tuInfo = "Creation date: " + sysFields.CreationUser + "\n"; tuInfo += "Creation user: "******"\n"; tuInfo += "Change date: " + sysFields.ChangeDate + "\n"; tuInfo += "Change user: "******"\n"; tuInfo += "Usage count: " + sysFields.UseCount + "\n"; tuInfo += "Last used on: " + sysFields.UseDate + "\n"; tuInfo += "Last used by: " + sysFields.UseUser + "\n"; break; } } MessageBox.Show(tuInfo, "TU Information"); #endregion }
public void ProcessReindexFileBasedTm(BackgroundWorker bw, TranslationMemoryInfo tm) { _reindexStatus.AppendLine(string.Format("Start reindex {0} translation memory", tm.Name)); bw.ReportProgress(0, _reindexStatus.ToString()); var fileBasedTm = new FileBasedTranslationMemory(tm.FilePath); if ((fileBasedTm.Recognizers & BuiltinRecognizers.RecognizeAlphaNumeric) == 0) { fileBasedTm.Recognizers |= BuiltinRecognizers.RecognizeAlphaNumeric; } var languageDirection = fileBasedTm.LanguageDirection; var iterator = new RegularIterator(100); while (languageDirection.ReindexTranslationUnits(ref iterator)) { if (!bw.CancellationPending) { bw.ReportProgress(0, _reindexStatus.ToString()); } else { bw.ReportProgress(100, ""); } } fileBasedTm.RecomputeFuzzyIndexStatistics(); fileBasedTm.Save(); _reindexStatus.AppendLine(string.Format("Finish reindex {0} translation memory", tm.Name)); bw.ReportProgress(0, _reindexStatus.ToString()); }
public void AddResource(string tmPath) { #region "open" FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath); #endregion #region "default" DefaultLanguageResourceProvider defaultBundle = new DefaultLanguageResourceProvider(); #endregion #region "newBundle" LanguageResourceBundle newBundle = defaultBundle.GetDefaultLanguageResources(CultureInfo.GetCultureInfo("en-US")); #endregion #region "abbreviations" newBundle.Abbreviations = new Wordlist(); newBundle.Abbreviations.Add("hr."); newBundle.Abbreviations.Add("cont."); #endregion #region "variables" newBundle.Variables = new Wordlist(); newBundle.Variables.Add("Mac OSX"); newBundle.Variables.Add("Microsoft Windows 7"); newBundle.Variables.Add("Suse Linux"); tm.LanguageResourceBundles.Add(newBundle); tm.Save(); #endregion }
public TranslationMemoryInfo(string tmFilePath, bool isStudioTm) { FilePath = tmFilePath; Uri = FileBasedTranslationMemory.GetFileBasedTranslationMemoryUri(tmFilePath); Name = FileBasedTranslationMemory.GetFileBasedTranslationMemoryName(Uri); IsStudioTm = isStudioTm; }
private void CopyTmFieldDefinitions(FileBasedTranslationMemory templateTm, FileBasedTranslationMemory tm) { foreach (FieldDefinition field in templateTm.FieldDefinitions) { tm.FieldDefinitions.Add(field.Clone()); } }
public FileInfo ExtractTestset() { FileBasedTranslationMemory tm = new FileBasedTranslationMemory(this.filteredTMPath); var tmLangdir = tm.GetLanguageDirection(tm.SupportedLanguageDirections.Single()); this.SourceLang = new Language(tmLangdir.SourceLanguage); this.TargetLang = new Language(tmLangdir.TargetLanguage); //Move the iterator to the end of the TM and go backwards to get the newest segments (although //order may not be based on insertion time) RegularIterator iterator = new RegularIterator { MaxCount = this.batchSize, Forward = false, PositionFrom = tmLangdir.GetTranslationUnitCount() }; List <TranslationUnit> finetuneTestset = new List <TranslationUnit>(); TranslationUnit[] tuBatch = tmLangdir.GetTranslationUnits(ref iterator); for (var batchIndex = 0; batchIndex < this.batches; batchIndex++) { tuBatch = tmLangdir.GetTranslationUnits(ref iterator); finetuneTestset.AddRange(tuBatch); foreach (var tu in tuBatch) { var success = tmLangdir.DeleteTranslationUnit(tu.ResourceId); } } FileInfo sourceFile = new FileInfo($"{this.masterTMNameWithoutExtension}_finetunetest_source.txt"); FileInfo targetFile = new FileInfo($"{this.masterTMNameWithoutExtension}_finetunetest_target.txt"); using (var sourceWriter = sourceFile.CreateText()) using (var targetWriter = targetFile.CreateText()) { foreach (var tu in finetuneTestset) { var plainSource = tu.SourceSegment.ToPlain(); var plainTarget = tu.TargetSegment.ToPlain(); if (!(plainSource.Contains("\n") || plainTarget.Contains("\n"))) { sourceWriter.WriteLine(tu.SourceSegment.ToPlain()); targetWriter.WriteLine(tu.TargetSegment.ToPlain()); } } } RegularIterator reindexIterator = new RegularIterator(); bool reindexInProgress = true; while (reindexInProgress) { reindexInProgress = tmLangdir.ReindexTranslationUnits(ref reindexIterator); } tm.Save(); return(sourceFile); }
public static void SetTm(string tmPath, string source, string target) { if (File.Exists(tmPath)) { FileTm = new FileBasedTranslationMemory(tmPath); } else { const BuiltinRecognizers recognizers = BuiltinRecognizers.RecognizeDates | BuiltinRecognizers.RecognizeMeasurements | BuiltinRecognizers.RecognizeNumbers | BuiltinRecognizers.RecognizeTimes; const TokenizerFlags tokenizerFlags = TokenizerFlags.DefaultFlags; FileTm = new FileBasedTranslationMemory(tmPath, string.Empty, new System.Globalization.CultureInfo(source), new System.Globalization.CultureInfo(target), new FuzzyIndexes(), new BuiltinRecognizers(), new TokenizerFlags(), new WordCountFlags()) { Recognizers = recognizers, TokenizerFlags = tokenizerFlags }; } }
/// <summary> /// Create the master TM based on the source and target locales found in the current TMX file. /// </summary> /// <param name="sourceLanguage">String representation of translation memory source language.</param> /// <param name="targetLanguage">String representation of translation memory target language.</param> /// <param name="masterPath">Path to translation memory.</param> public void CreateMasterTm(string sourceLanguage, string targetLanguage, string masterPath) { #region "Create Translation Memory" string path = string.Format( CultureInfo.CurrentCulture, "{0}MasterTm_{1}_{2}.sdltm", masterPath, sourceLanguage, targetLanguage); FileBasedTranslationMemory translationMemory = new FileBasedTranslationMemory( path, "Master TM", CultureInfo.GetCultureInfo(sourceLanguage), CultureInfo.GetCultureInfo(targetLanguage), this.GetFuzzyIndexes(), this.GetRecognizers(), TokenizerFlags.AllFlags, WordCountFlags.AllFlags ); #endregion #region "Save" translationMemory.LanguageResourceBundles.Clear(); translationMemory.Save(); #endregion }
private FileBasedTranslationMemory CreateTranslationMemory() { var tmPath = GetTemporaryTmPath(); if (File.Exists(tmPath)) { var existingTm = new FileBasedTranslationMemory(tmPath); if (Equals(existingTm.LanguageDirection.SourceLanguage, _settings.SourceLanguage) && Equals(existingTm.LanguageDirection.TargetLanguage, _settings.TargetLanguage) && existingTm.Recognizers == _settings.Recognizers && existingTm.TokenizerFlags == _settings.TokenizerFlags && existingTm.WordCountFlags == _settings.WordCountFlags) { return(existingTm); } } var temporaryTm = new FileBasedTranslationMemory(tmPath , "Temporary TM" , _settings.SourceLanguage , _settings.TargetLanguage , FuzzyIndexes.SourceWordBased , _settings.Recognizers , _settings.TokenizerFlags , _settings.WordCountFlags , false); temporaryTm.FieldDefinitions.Add(new FieldDefinition("FileIndex", FieldValueType.Integer)); temporaryTm.Save(); return(temporaryTm); }
public void AddFields(string tmPath) { #region "listField" FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath); FieldDefinition listField = new FieldDefinition { Name = "Customer", ValueType = FieldValueType.MultiplePicklist }; listField.PicklistItems.Add("SDL"); listField.PicklistItems.Add("Microsoft"); #endregion #region "textField" FieldDefinition textField = new FieldDefinition { Name = "Project id", ValueType = FieldValueType.MultipleString }; #endregion #region "add" tm.FieldDefinitions.Add(listField); tm.FieldDefinitions.Add(textField); #endregion tm.Save(); }
/// <summary> /// Checks if TM found in the template supports any language from Transit Packages /// </summary> /// <param name="tmLocalPath">Tm local path read from project template</param> /// <param name="sourceCultureInfo">Package source language</param> /// <param name="targetLanguages">Package target languages</param> /// <returns>true and target language supported</returns> /// <returns>false if the TM target language is not supported by Transit Package</returns> public (bool, Language) TmSupportsAnyLanguageDirection(Uri tmLocalPath, CultureInfo sourceCultureInfo, Language[] targetLanguages) { if (sourceCultureInfo is null || targetLanguages is null) { return(false, null); } var tm = new FileBasedTranslationMemory(tmLocalPath); var tmSupportedLanguages = tm.SupportedLanguageDirections; foreach (var supportedLanguageDirection in tmSupportedLanguages) { var isTmSourceLanguageSupported = sourceCultureInfo.Name.Equals(supportedLanguageDirection.SourceCultureName); if (!isTmSourceLanguageSupported) { return(false, null); } var correspondingTarget = targetLanguages.FirstOrDefault(t => t.CultureInfo.Name.Equals(supportedLanguageDirection.TargetCultureName)); if (correspondingTarget != null) { return(true, correspondingTarget); } } return(false, null); }
public static void AnonymizeFileBasedTu(List <AnonymizeTranslationMemory> tusToAnonymize) { foreach (var translationUnitPair in tusToAnonymize) { var tm = new FileBasedTranslationMemory(translationUnitPair.TmPath); foreach (var translationUnit in translationUnitPair.TranslationUnits) { var sourceTranslationElements = translationUnit.SourceSegment.Elements.ToList(); var elementsContainsTag = sourceTranslationElements.Any(s => s.GetType().UnderlyingSystemType.Name.Equals("Tag")); if (elementsContainsTag) { AnonymizeSegmentsWithTags(translationUnit, sourceTranslationElements, true); } else { AnonymizeSegmentsWithoutTags(translationUnit, sourceTranslationElements, true); } translationUnit.SystemFields.CreationUser = "******"; translationUnit.SystemFields.UseUser = "******"; tm.LanguageDirection.UpdateTranslationUnit(translationUnit); } // //foreach (FieldValue item in translationUnit.FieldValues) // //{ // // var anonymized = AnonymizeData.EncryptData(item.GetValueString(), "Andrea"); // // item.Clear(); // // item.Add(anonymized); // //} // //var test = translationUnit.DocumentSegmentPair //} } }
public List <TmDetails> LoadLocalUserTms() { var localTms = new List <TmDetails>(); var xmlDocument = new XmlDocument(); xmlDocument.Load(_tmsConfigPath); if (xmlDocument.DocumentElement == null) { return(null); } var tmNodes = xmlDocument.SelectNodes("/TranslationMemoryRepository/TranslationMemories/TranslationMemory"); if (tmNodes != null) { foreach (XmlElement tmNode in tmNodes) { var tmPath = tmNode.GetAttribute("path"); if (!string.IsNullOrEmpty(tmPath)) { var tm = new FileBasedTranslationMemory(tmPath); var tmDetails = new TmDetails { TmPath = tmPath, Name = tm.Name, SourceFlag = new Language(tm.LanguageDirection.SourceLanguage.Name).GetFlagImage(), TargetFlag = new Language(tm.LanguageDirection.TargetLanguage.Name).GetFlagImage(), FileBasedTranslationMemory = tm }; localTms.Add(tmDetails); } } } return(localTms); }
/// <summary> /// creates new importer, sets importer settings /// </summary> /// <param name="tm">TM to import to</param> /// <param name="settings">import settings</param> public Importer(FileBasedTranslationMemory tm, DataImportSettings settings) { _settings = settings; _importer = new TranslationMemoryImporter(tm.LanguageDirection); ChangeSettings(); }
/// <summary> /// The SegmentPair processer offers the possiblity to recover additional information from the ISegmentPair (FileTypeSupport.Framework) /// through the LanguagePlatform, that includes the tokenized segments and word counts /// </summary> /// <param name="settings">Settings used primarily to setup the translation memory</param> /// <param name="pathInfo">Path information</param> public SegmentPairProcessor(Settings settings, PathInfo pathInfo) { _settings = settings; _pathInfo = pathInfo; _temporaryTm = CreateTranslationMemory(); }
protected virtual void Dispose(bool disposing) { if (disposing) { _filebasedTmIn = null; _fileBasedTmOut = null; } }
private List <TemplateTmDetails> TmDetailsFromCascadeEntry(XmlDocument projectTemplateDocument, CultureInfo sourceCultureInfo, Language[] targetLanguages) { if (sourceCultureInfo is null || targetLanguages is null) { return(null); } var cascadeEntries = projectTemplateDocument.SelectNodes("/ProjectTemplate/CascadeItem/CascadeEntryItem"); if (cascadeEntries is null) { return(null); } var tmDetails = new List <TemplateTmDetails>(); foreach (XmlNode cascadeEntryItem in cascadeEntries) { var details = new TemplateTmDetails(); if (cascadeEntryItem.Attributes is null) { continue; } foreach (XmlAttribute entryAttribute in cascadeEntryItem.Attributes) { if (!entryAttribute.Name.Equals("Penalty")) { continue; } int.TryParse(entryAttribute.Value, out var penaltySet); details.Penalty = penaltySet; foreach (XmlNode mainTranslationProviderItem in cascadeEntryItem.ChildNodes) { if (mainTranslationProviderItem.Attributes is null) { continue; } foreach (XmlAttribute providerAttribute in mainTranslationProviderItem.Attributes) { if (!providerAttribute.Name.Equals("Uri")) { continue; } var uri = new Uri(providerAttribute.Value); details.LocalPath = FileBasedTranslationMemory.GetFileBasedTranslationMemoryFilePath(uri); details.Name = Path.GetFileNameWithoutExtension(details.LocalPath); details.TransitLanguagePairOptions = GetLanguagePairTmOptions(details, sourceCultureInfo, targetLanguages); } } } if (details.TransitLanguagePairOptions != null) { tmDetails.Add(details); } } return(tmDetails); }
public static void UpdateTranslationMemory(FileBasedTranslationMemory tm) { if (tm.FGASupport == FGASupport.NonAutomatic) { return; } tm.Save(); }
/// <summary> /// create new TMFileManager /// </summary> /// <param name="filePath">source file path to process</param> public TMFileManager(string filePath) { TMFilePath = filePath; ValidateTMFilePath(); _tm = new FileBasedTranslationMemory(TMFilePath); TUsCount = _tm.GetTranslationUnitCount(); }
protected override void ExecuteImpl() { CultureInfo sourceCulture; CultureInfo targetCulture; FuzzyIndexes fuzzyIndexes; BuiltinRecognizers recognizers; if (_templateTranslationMemory != null && _templateTranslationMemory.FilePath != null) { sourceCulture = _templateTranslationMemory.TranslationMemory.LanguageDirection.SourceLanguage; targetCulture = _templateTranslationMemory.TranslationMemory.LanguageDirection.TargetLanguage; fuzzyIndexes = _templateTranslationMemory.TranslationMemory.FuzzyIndexes; recognizers = _templateTranslationMemory.TranslationMemory.Recognizers; } else { sourceCulture = _sourceLanguage.CultureInfo; targetCulture = _targetLanguage.CultureInfo; fuzzyIndexes = FuzzyIndexes.SourceWordBased | FuzzyIndexes.TargetWordBased; recognizers = BuiltinRecognizers.RecognizeAll; } FileBasedTranslationMemory tm = new FileBasedTranslationMemory( _tm.FilePath, String.Empty, sourceCulture, targetCulture, fuzzyIndexes, recognizers); ReportProgress(25); tm.Save(); ReportProgress(50); if (_templateTranslationMemory != null && _templateTranslationMemory.FilePath != null) { CopyTmLanguageResources(_templateTranslationMemory.TranslationMemory, tm); CopyTmFieldDefinitions(_templateTranslationMemory.TranslationMemory, tm); } ReportProgress(75); tm.Save(); ReportProgress(100); }
private void CopyTmLanguageResources(FileBasedTranslationMemory templateTm, FileBasedTranslationMemory tm) { ITranslationMemoryLanguageDirection languageDirection = tm.LanguageDirection; // Copy any sourcelanguage resources from the template tm to the new tm LanguageResourceBundle sourceLanguageBundle = templateTm.LanguageResourceBundles[languageDirection.SourceLanguage]; if (sourceLanguageBundle != null) { tm.LanguageResourceBundles.Add(sourceLanguageBundle.Clone()); } // Copy any target language resources from the template tm to the new tm LanguageResourceBundle targetLanguageBundle = templateTm.LanguageResourceBundles[languageDirection.TargetLanguage]; if (targetLanguageBundle != null) { tm.LanguageResourceBundles.Add(targetLanguageBundle.Clone()); } }
public ExportStudioTmStep(FileBasedTranslationMemory translationMemory, TmxFile exportTmxFile) : base(String.Format("Exporting translation memory {0}", translationMemory.Name)) { _translationMemory = translationMemory; _exportTmxFile = exportTmxFile; }