public List <string> GetFilesNamesFromPrjFile(List <KeyValuePair <string, string> > files) { var fileNames = new List <string>(); if (files != null) { foreach (var file in files) { var splitedValues = file.Value.Split('|'); var fileName = splitedValues[splitedValues.Length - 3]; var fileExists = fileNames.Any(f => f.Equals(fileName)); if (!fileExists) { fileNames.Add(fileName); } } } else { _eventAggregatorService?.PublishEvent(new Error { ErrorMessage = Resources.NoFilesFromPrj }); _logger.Error("Could read any files information from [File]"); } return(fileNames); }
/// <summary> /// Create temporary bilingual files (sdlxliff) used to import the information in Studio translation memories /// </summary> private string CreateTemporarySdlXliffs(List <string> sourceTmFiles, List <string> targetTmFiles, CultureInfo targetCultureInfo, PackageModel package) { var pathToExtractFolder = CreateFolderToExtract(Path.GetDirectoryName(targetTmFiles[0])); var targetLang = new Language(targetCultureInfo); var projectInfo = new ProjectInfo { Name = $"TMExtractProject_{Guid.NewGuid()}", LocalProjectFolder = pathToExtractFolder, SourceLanguage = new Language(package.LanguagePairs[0].SourceLanguage), TargetLanguages = new[] { targetLang } }; var newProject = new FileBasedProject(projectInfo, new ProjectTemplateReference(package.ProjectTemplate.Uri)); newProject.AddFiles(sourceTmFiles.ToArray()); var sourceFilesIds = newProject.GetSourceLanguageFiles().GetIds(); newProject.SetFileRole(sourceFilesIds, FileRole.Translatable); var targetTms = newProject.AddFiles(targetTmFiles.ToArray()); newProject.RunAutomaticTask(targetTms?.GetIds(), AutomaticTaskTemplateIds.Scan); var xliffCreationProgress = new XliffCreationProgress { BatchTaskIds = new List <string>(), TargetLanguage = targetLang.CultureInfo, TotalFileNumber = sourceTmFiles.Count }; var taskSequence = newProject.RunAutomaticTasks(targetTms?.GetIds(), new[] { AutomaticTaskTemplateIds.ConvertToTranslatableFormat, AutomaticTaskTemplateIds.CopyToTargetLanguages }, (sender, args) => { xliffCreationProgress.BatchTaskIds.Clear(); xliffCreationProgress.BatchTaskIds.AddRange(args.TaskTemplateIds); xliffCreationProgress.Progress = args.PercentComplete; _eventAggregator.PublishEvent(xliffCreationProgress); }, (sender, args) => { }); if (taskSequence.Status != TaskStatus.Failed) { return(pathToExtractFolder); } foreach (var subTask in taskSequence.SubTasks) { _logger.Error($"Name:{subTask.Name}"); foreach (var messages in subTask.Messages) { _logger.Error($"Exception: {messages?.Exception}"); _logger.Error($"Message: {messages?.Message}"); } } return(string.Empty); }
public virtual MessageModel UpdateProjectSettings(IProject project, Guid[] targetFilesIds, bool projectContainsTm, CultureInfo targetLanguage) { var fileBasedProject = (FileBasedProject)project; if (projectContainsTm) { UpdateTmSettings(project); fileBasedProject.UpdateTranslationProviderConfiguration(_tmConfig); } var projectCreationProgress = new ProjectCreationProgress { BatchTaskIds = new List <string>() }; project.RunAutomaticTask(targetFilesIds, AutomaticTaskTemplateIds.Scan); var taskSequence = fileBasedProject.RunAutomaticTasks(targetFilesIds, new[] { AutomaticTaskTemplateIds.ConvertToTranslatableFormat, AutomaticTaskTemplateIds.CopyToTargetLanguages, AutomaticTaskTemplateIds.PreTranslateFiles, }, (sender, args) => { projectCreationProgress.BatchTaskIds.Clear(); projectCreationProgress.BatchTaskIds.AddRange(args.TaskTemplateIds); projectCreationProgress.Progress = args.PercentComplete; projectCreationProgress.TargetLanguage = targetLanguage; _eventAggregatorService.PublishEvent(projectCreationProgress); }, (sender, args) => { }); if (taskSequence.Status.Equals(TaskStatus.Failed)) { _messageModel.IsProjectCreated = false; foreach (var subTask in taskSequence.SubTasks) { _logger.Error($"Name:{subTask.Name}"); foreach (var messages in subTask.Messages) { _logger.Error($"Exception: {messages?.Exception}"); _logger.Error($"Message: {messages?.Message}"); } } throw new Exception("Project could not be created.Error occurred while running create project automatic task."); } fileBasedProject.Save(); return(_messageModel); }
private void ImportSdlXliffsIntoTm(string sdlXliffFolderPath, CultureInfo targetLanguage) { try { ConfirmationLevel[] levels = { ConfirmationLevel.ApprovedTranslation, ConfirmationLevel.Translated, ConfirmationLevel.ApprovedSignOff }; var importSettings = new ImportSettings { IsDocumentImport = true, CheckMatchingSublanguages = false, IncrementUsageCount = true, NewFields = ImportSettings.NewFieldsOption.AddToSetup, PlainText = false, ExistingTUsUpdateMode = ImportSettings.TUUpdateMode.AddNew, ConfirmationLevels = levels }; var tmImporter = new TranslationMemoryImporter(_translationMemory.LanguageDirection) { ImportSettings = importSettings }; var folderPath = Path.Combine(sdlXliffFolderPath, targetLanguage.Name); if (!Directory.Exists(folderPath)) { return; } var xliffFiles = Directory.GetFiles(folderPath); var tmFileProgress = new TmFilesProgress { TotalFilesNumber = xliffFiles.Length, TargetLanguage = targetLanguage }; foreach (var xliffFile in xliffFiles) { tmFileProgress.ProcessingFileNumber++; tmImporter.Import(xliffFile); _eventAggregator?.PublishEvent(tmFileProgress); } } catch (Exception ex) { _logger.Error(ex); } }