private File GetFileContainer(IParagraphUnit paragraphUnit)
        {
            var contextType = GetContextType(paragraphUnit);
            var file        = Xliff.Files[Xliff.Files.Count - 1];

            if (contextType != null)
            {
                if (contextType != "Recommended")
                {
                    var alternativeFile = Xliff.Files.FirstOrDefault(a => a.Original == contextType);
                    if (alternativeFile != null)
                    {
                        file = alternativeFile;
                    }
                    else
                    {
                        file = new File
                        {
                            Original       = contextType,
                            SourceLanguage = SourceLanguage.Name,
                            TargetLanguage = TargetLanguage.Name,
                            DataType       = "xml"
                        };
                        Xliff.Files.Add(file);
                    }
                }
                else
                {
                    file.Original = "Recommended";
                }
            }

            return(file);
        }
        public override void SetFileProperties(IFileProperties fileInfo)
        {
            _fileProperties = fileInfo;

            var file = new File
            {
                SourceLanguage = SourceLanguage.Name,
                TargetLanguage = TargetLanguage.Name
            };

            file.Original = fileInfo.FileConversionProperties.OriginalFilePath;
            file.DataType = fileInfo.FileConversionProperties.FileTypeDefinitionId.Id;

            Xliff.Files.Add(file);

            CreateDummyOutputFiles(fileInfo);
        }
        private void UpdateContexts(File file, IParagraphUnit paragraphUnit, TransUnit transUnit)
        {
            if (paragraphUnit.Properties.Contexts?.Contexts != null)
            {
                foreach (var context in paragraphUnit.Properties.Contexts.Contexts)
                {
                    var existingContext = file.Header.Contexts.FirstOrDefault(a =>
                                                                              string.Compare(a.ContextType, context.ContextType, StringComparison.CurrentCultureIgnoreCase) == 0 &&
                                                                              string.Compare(a.DisplayCode, context.DisplayCode, StringComparison.CurrentCultureIgnoreCase) == 0 &&
                                                                              string.Compare(a.DisplayName, context.DisplayName, StringComparison.CurrentCultureIgnoreCase) == 0 &&
                                                                              string.Compare(a.Description, context.Description, StringComparison.CurrentCultureIgnoreCase) == 0);

                    if (existingContext != null)
                    {
                        transUnit.Contexts.Add(existingContext);
                    }
                    else
                    {
                        _contextIndex++;

                        var newContext = new Context
                        {
                            Id          = _contextIndex.ToString(),
                            ContextType = context.ContextType,
                            Description = context.Description,
                            DisplayCode = context.DisplayCode,
                            DisplayName = context.DisplayName
                        };

                        if (context.MetaData != null)
                        {
                            foreach (var metaData in context.MetaData)
                            {
                                newContext.MetaData.Add(metaData.Key, metaData.Value);
                            }
                        }

                        transUnit.Contexts.Add(newContext);
                        file.Header.Contexts.Add(newContext);
                    }
                }
            }
        }
Beispiel #4
0
        private static SegmentPair GetBackTranslationSegmentPair(File backTranslationDataFile, SegmentPair segmentPair)
        {
            if (backTranslationDataFile?.Body == null)
            {
                return(null);
            }

            foreach (var transUnit in backTranslationDataFile.Body.TransUnits)
            {
                foreach (var pair in transUnit.SegmentPairs)
                {
                    if (pair.Id == segmentPair.Id)
                    {
                        return(pair);
                    }
                }
            }

            return(null);
        }
        public void SetFileProperties(IFileProperties fileInfo)
        {
            _fileProperties = fileInfo;

            var file = new File
            {
                SourceLanguage = SourceLanguage.Name,
                TargetLanguage = TargetLanguage.Name
            };

            var originalFilePath = fileInfo.FileConversionProperties.OriginalFilePath ??
                                   fileInfo.FileConversionProperties.InputFilePath;

            var systemFileInfo = new FileInfo(originalFilePath);

            file.Original = fileInfo.FileConversionProperties.OriginalFilePath;
            //file.DataType = systemFileInfo.Extension;
            file.DataType = fileInfo.FileConversionProperties.FileTypeDefinitionId.Id;

            //var addedExternalDependency = false;
            //foreach (var dependencyFile in fileInfo.FileConversionProperties.DependencyFiles)
            //{
            //	if (!addedExternalDependency &&
            //		dependencyFile.PreferredLinkage != DependencyFileLinkOption.Embed)
            //	{
            //		addedExternalDependency = true;
            //		var externalFile = new ExternalFile
            //		{
            //			Uid = dependencyFile.Id,
            //			Href = dependencyFile.CurrentFilePath ??
            //				   dependencyFile.OriginalFilePath ?? dependencyFile.PathRelativeToConverted
            //		};
            //		file.Header.Skl.ExternalFile = externalFile;
            //	}
            //}

            Xliff.Files.Add(file);

            CreateDummyOutputFiles(fileInfo);
        }