Пример #1
0
        protected override void ExecuteCore()
        {
            string sourcePath         = XlfFile.GetMetadataOrThrow(MetadataKey.XlfSource);
            string sourceFormat       = XlfFile.GetMetadataOrThrow(MetadataKey.XlfSourceFormat);
            string language           = XlfFile.GetMetadataOrThrow(MetadataKey.XlfLanguage);
            string translatedFullPath = XlfFile.GetMetadataOrThrow(MetadataKey.XlfTranslatedFullPath);

            TranslatableDocument sourceDocument = LoadSourceDocument(sourcePath, XlfFile.GetMetadata(MetadataKey.XlfSourceFormat));
            XlfDocument          xlfDocument    = LoadXlfDocument(XlfFile.ItemSpec);

            bool validationFailed = false;

            xlfDocument.Validate(validationError =>
            {
                validationFailed = true;
                Log.LogErrorInFile(XlfFile.ItemSpec, validationError.LineNumber, validationError.Message);
            });

            IReadOnlyDictionary <string, string> translations = validationFailed
                ? new Dictionary <string, string>()
                : xlfDocument.GetTranslations();

            sourceDocument.Translate(translations);

            Directory.CreateDirectory(Path.GetDirectoryName(translatedFullPath));

            sourceDocument.RewriteRelativePathsToAbsolute(Path.GetFullPath(sourcePath));
            sourceDocument.Save(translatedFullPath);
        }
Пример #2
0
        public object Clone()
        {
            var documentActivities = new DocumentActivities
            {
                Id = Id,
                TranslatableDocument = (Document)TranslatableDocument.Clone()
            };


            if (Activities != null)
            {
                documentActivities.Activities = new List <DocumentActivity>();
                foreach (var da in Activities)
                {
                    documentActivities.Activities.Add((DocumentActivity)da.Clone());
                }
            }
            else
            {
                documentActivities.Activities = null;
            }


            return(documentActivities);
        }
Пример #3
0
        public object Clone()
        {
            var tca = new DocumentActivity
            {
                Id = Id,
                DocumentActivityType = DocumentActivityType,
                ProjectActivityId    = ProjectActivityId,
                DocumentId           = DocumentId,
                TranslatableDocument = (Document)TranslatableDocument.Clone(),
                ProjectId            = ProjectId,
                Started       = Started,
                Stopped       = Stopped,
                TicksActivity = TicksActivity,
                TicksRecords  = TicksRecords,
                WordCount     = WordCount,
                Records       = new List <Record>()
            };



            foreach (var tcr in Records)
            {
                tca.Records.Add((Record)tcr.Clone());
            }

            tca.DocumentStateCounters = (DocumentStateCounters)DocumentStateCounters.Clone();



            return(tca);
        }
Пример #4
0
        protected override void ExecuteCore()
        {
            foreach (var item in Sources)
            {
                string sourcePath                   = item.ItemSpec;
                string sourceDocumentPath           = item.GetMetadataOrDefault(MetadataKey.SourceDocumentPath, item.ItemSpec);
                string sourceFormat                 = item.GetMetadataOrThrow(MetadataKey.XlfSourceFormat);
                TranslatableDocument sourceDocument = LoadSourceDocument(sourcePath, sourceFormat);
                string sourceDocumentId             = GetSourceDocumentId(sourcePath);

                foreach (var language in Languages)
                {
                    string      xlfPath = GetXlfPath(sourceDocumentPath, language);
                    XlfDocument xlfDocument;

                    try
                    {
                        xlfDocument = LoadXlfDocument(xlfPath, language, createIfNonExistent: AllowModification);
                    }
                    catch (FileNotFoundException fileNotFoundEx) when(fileNotFoundEx.FileName == xlfPath)
                    {
                        Release.Assert(!AllowModification);
                        throw new BuildErrorException($"'{xlfPath}' for '{sourcePath}' does not exist. {HowToUpdate}");
                    }
                    catch (System.Xml.XmlException xmlEx)
                    {
                        throw new BuildErrorException($"Unable to load file: {xmlEx.Message}")
                              {
                                  RelatedFile = xlfPath
                              };
                    }

                    bool updated = xlfDocument.Update(sourceDocument, sourceDocumentId);

                    if (!updated)
                    {
                        continue; // no changes
                    }

                    if (!AllowModification)
                    {
                        throw new BuildErrorException($"'{xlfPath}' is out-of-date with '{sourcePath}'. {HowToUpdate}");
                    }

                    Directory.CreateDirectory(Path.GetDirectoryName(xlfPath));
                    xlfDocument.Save(xlfPath);
                }
            }
        }
Пример #5
0
        protected override void ExecuteCore()
        {
            string sourcePath         = XlfFile.GetMetadataOrThrow(MetadataKey.XlfSource);
            string sourceFormat       = XlfFile.GetMetadataOrThrow(MetadataKey.XlfSourceFormat);
            string language           = XlfFile.GetMetadataOrThrow(MetadataKey.XlfLanguage);
            string translatedFullPath = XlfFile.GetMetadataOrThrow(MetadataKey.XlfTranslatedFullPath);

            TranslatableDocument sourceDocument = LoadSourceDocument(sourcePath, XlfFile.GetMetadata(MetadataKey.XlfSourceFormat));
            XlfDocument          xlfDocument    = LoadXlfDocument(XlfFile.ItemSpec);

            sourceDocument.Translate(xlfDocument.GetTranslations());

            Directory.CreateDirectory(Path.GetDirectoryName(translatedFullPath));
            sourceDocument.Save(translatedFullPath);
        }
Пример #6
0
        public object Clone()
        {
            var documentActivities = new DocumentActivities
            {
                Id = Id,
                ProjectActivityId     = ProjectActivityId,
                DocumentId            = DocumentId,
                TranslatableDocument  = (Document)TranslatableDocument.Clone(),
                DocumentActivityTicks = DocumentActivityTicks,
                DocumentRecordsTicks  = DocumentRecordsTicks,
                DocumentActivityIds   = new List <int>()
            };



            foreach (var value in DocumentActivityIds)
            {
                documentActivities.DocumentActivityIds.Add(value);
            }


            return(documentActivities);
        }