Ejemplo n.º 1
0
        private string GetTranslatedOutputPath(ITaskItem source, string language, HashSet <string> outputPaths)
        {
            string translatedFilename = source.GetMetadata(MetadataKey.XlfTranslatedFilename);

            if (string.IsNullOrEmpty(translatedFilename))
            {
                translatedFilename = Path.GetFileNameWithoutExtension(source.ItemSpec);
                source.SetMetadata(MetadataKey.XlfTranslatedFilename, translatedFilename);
            }

            string sourceDocumentPath = source.GetMetadataOrDefault(MetadataKey.SourceDocumentPath, source.ItemSpec);
            string extension          = Path.GetExtension(source.ItemSpec);
            string outputPath         = Path.Combine(TranslatedOutputDirectory, $"{translatedFilename}.{language}{extension}");

            if (!outputPaths.Add(outputPath))
            {
                throw new BuildErrorException(
                          $"Two or more source files to be translated in the same project are named {Path.GetFileName(sourceDocumentPath)}. " +
                          $"Give them unique names or set unique {MetadataKey.XlfTranslatedFilename} metadata.");
            }

            return(outputPath);
        }