Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }