예제 #1
0
        private static int Main([NotNull] string[] args)
        {
#if DEBUG
            // Allow to attach debugger
            Console.ReadLine();
#endif // DEBUG
            if (args.Length == 0)
            {
                ShowUsage();
                return(-1);
            }

            if (!ParseOptions(args, out var options, out var message))
            {
                Console.WriteLine(message.ToString());
                return(-1);
            }

            if (options.ShowUsage)
            {
                ShowUsage();
                return(0);
            }

            if (!CheckOptions(options, out message))
            {
                Console.WriteLine(message.ToString());
                return(-1);
            }

            try
            {
                // Initialize translation
                TranslationManager.Instance.RegisterProvider(new GettextTranslationProvider());

                // Compute the list of input files
                ISet <UFile> inputFiles = new HashSet <UFile>();
                var          re         = options.Excludes.Count > 0 ? new Regex(string.Join("|", options.Excludes.Select(x => Regex.Escape(x).Replace(@"\*", @".*")))) : null;
                foreach (var path in options.InputDirs)
                {
                    foreach (var searchPattern in options.InputFiles)
                    {
                        var files = Directory.EnumerateFiles(path, searchPattern, options.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                    .Where(f => !re?.IsMatch(f) ?? true);
                        foreach (var fileName in files)
                        {
                            inputFiles.Add(new UFile(fileName));
                        }
                    }
                }
                // Extract all messages from the input files
                var messages = new List <Message>();
                messages.AddRange(new CSharpExtractor(inputFiles).ExtractMessages());
                messages.AddRange(new XamlExtractor(inputFiles).ExtractMessages());
                if (options.Verbose)
                {
                    Console.WriteLine(Tr._n("Found {0} message.", "Found {0} messages.", messages.Count), messages.Count);
                }
                // Export/merge messages
                var exporter = new POExporter(options);
                exporter.Merge(messages);
                exporter.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(Tr._("Error during execution: {0}"), ex.Message);
                return(1);
            }

            return(0);
        }