Пример #1
0
        public static int Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            StringBuilder message;

            Options options = new Options();

            if (args.Length == 0)
            {
                PrintUsage();
                return(1);
            }
            else if (!GetOptions(args, SOpts, LOpts, options, out message))
            {
                Console.WriteLine(message.ToString());
                return(1);
            }
            else if (options.ShowUsage)
            {
                PrintUsage();
                return(0);
            }
            if (!AnalyseOptions(options, out message))
            {
                Console.WriteLine(message.ToString());
                return(1);
            }

            try
            {
                ExtractorCsharp extractor = new ExtractorCsharp(options);
                extractor.GetMessages();
                extractor.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during execution: {0}", ex.Message);
                return(1);
            }

            Console.WriteLine("Template file '{0}' generated", options.OutFile);
            return(0);
        }
Пример #2
0
        public void ExtractorCSharpTest()
        {
            string ressourceId = String.Format("{0}.{1}", this.GetType().Assembly.GetName().Name, "Data.XgettextTest.txt");
            string text = "";
            using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(ressourceId))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    text = reader.ReadToEnd();
                }
            }

            Options options = new Options();
            options.InputFiles.Add(@"./Test/File/Name.cs"); // File wont be used, feed the plain text
            options.OutFile = @"./Test.pot";
            options.Overwrite = true;
            ExtractorCsharp extractor = new ExtractorCsharp(options);
            extractor.GetMessages(text, options.InputFiles[0]);
            extractor.Save();

            int ctx = 0;
            int multiline = 0;
            foreach(CatalogEntry entry in extractor.Catalog)
            {
                if (entry.HasContext)
                    ctx++;
                if (entry.String == "multiline-string-1-string-2" ||
                    entry.String == "Multiline Hint for label1")
                    multiline++;
            }

            Assert.AreEqual(2, ctx, "Context count");

            Assert.AreEqual(2, extractor.Catalog.PluralFormsCount, "PluralFormsCount");
            Assert.AreEqual(17, extractor.Catalog.Count, "Duplicates may not detected");
            Assert.AreEqual(2, multiline, "Multiline string");
        }
Пример #3
0
        public static int Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            StringBuilder message;

            Options options = new Options();
            if (args.Length == 0)
            {
                PrintUsage();
                return 1;
            }
            else if (!GetOptions(args, SOpts, LOpts, options, out message))
            {
                Console.WriteLine(message.ToString());
                return 1;
            }
            else if (options.ShowUsage)
            {
                PrintUsage();
                return 0;
            }
            if (!AnalyseOptions(options, out message))
            {
                Console.WriteLine(message.ToString());
                return 1;
            }

            try
            {
                ExtractorCsharp extractor = new ExtractorCsharp(options);
                extractor.GetMessages();
                extractor.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during execution: {0}", ex.Message);
                return 1;
            }

            Console.WriteLine("Template file '{0}' generated", options.OutFile);
            return 0;
        }