Example #1
0
        protected TextManager()
        {
            //TODO: Point of interest. Avoid defaults? Read from configuration? Neither?

            Dialects = new Dictionary <string, PatternDialect>();
            Dialects.Add("Default", new DefaultDialect());
            Dialects.Add("Text", new TextDialect());

            Texts = new TextSourceAggregator();
            Texts.TextsChanged += SourceTextsChanged;

            FallbackNamespaces = new List <string>();
        }
Example #2
0
        static void Main(string[] args)
        {
            var extractOptions = new ExtractOptions();
            var compareOptions = new CompareOptions();
            var parser = new CommandLineParser();

            if( args.Length > 0 )
            {
                if (args[0] == "extract")
                {
                    if (parser.ParseArguments(args, extractOptions))
                    {
                        extractOptions.RootDirectory = extractOptions.RootDirectory ??
                            Environment.CurrentDirectory;

                        Console.Out.WriteLine("");
                        Console.Out.WriteLine("Extracting entries from:");
                        Console.Out.WriteLine("\"" + extractOptions.RootDirectory + "\"");
                        Console.Out.WriteLine("Extensions: " + string.Join(", ", extractOptions.Extensions));
                        Console.Out.WriteLine("Exclude patterns: " + string.Join(", ", extractOptions.ExcludePatterns));
                        Console.Out.WriteLine();
                        Console.Out.WriteLine("Saving texts to: " + extractOptions.TargetFile);

                        var extractor = new CStyleLanguageTextExtractor();
                        extractor.MarkerLanguage = extractOptions.DefaultLanguage;

                        extractor.SourceFiles = new SourceFileList(
                            extractOptions.RootDirectory,
                            extractOptions.Extensions,
                            extractOptions.ExcludePatterns).GetFiles();

                        var target = new XmlTextSource();
                        target.Put(extractor.Get().Select(x =>
                            new LocalizedTextState { Text = x, Status = LocalizedTextStatus.New }), TextMergeOptions.KeepUnused);

                        target.Document.Save(extractOptions.TargetFile);

                        return;
                    }
                }
                else if (args[0] == "compare")
                {
                    if (parser.ParseArguments(args, compareOptions))
                    {

                        Console.WriteLine();

                        var texts = new TextSourceAggregator();
                        using (texts.BeginUpdate())
                        {
                            foreach (var file in compareOptions.Files)
                            {
                                texts.Sources.Add(new PrioritizedTextSource(new XmlTextSource(XDocument.Load(file)), 1));
                            }
                        }
                        

                        var comparer = new LanguageComparer(texts);
                        var result = comparer.Compare(
                            compareOptions.SourceLanguage, 
                            compareOptions.TargetLanguage);
                        
                        Console.WriteLine(result.Success ?
                            "OK - The text(s) defines the same keys for the languages" :
                            "The two languages differ");
                        Console.Out.WriteLine();                        
                        foreach (var text in result.MissingTexts)
                        {
                            Console.Out.WriteLine("Missing\t" + text.Key);                            
                        }
                        foreach (var text in result.UnmatchedTexts)
                        {
                            Console.Out.WriteLine("Unmatched\t" + text.Key);                            
                        }                        
                        return;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine("Usage: ");
            Console.WriteLine();
            Console.WriteLine("Localization.exe extract");
            WriteHelp(extractOptions);
            Console.WriteLine();
            Console.WriteLine("Localization.exe compare");
            WriteHelp(compareOptions);
            Console.WriteLine();
        }
Example #3
0
        static void Main(string[] args)
        {
            var extractOptions = new ExtractOptions();
            var compareOptions = new CompareOptions();
            var parser         = new CommandLineParser();

            if (args.Length > 0)
            {
                if (args[0] == "extract")
                {
                    if (parser.ParseArguments(args, extractOptions))
                    {
                        extractOptions.RootDirectory = extractOptions.RootDirectory ??
                                                       Environment.CurrentDirectory;

                        Console.Out.WriteLine("");
                        Console.Out.WriteLine("Extracting entries from:");
                        Console.Out.WriteLine("\"" + extractOptions.RootDirectory + "\"");
                        Console.Out.WriteLine("Extensions: " + string.Join(", ", extractOptions.Extensions));
                        Console.Out.WriteLine("Exclude patterns: " + string.Join(", ", extractOptions.ExcludePatterns));
                        Console.Out.WriteLine();
                        Console.Out.WriteLine("Saving texts to: " + extractOptions.TargetFile);

                        var extractor = new CStyleLanguageTextExtractor();
                        extractor.MarkerLanguage = extractOptions.DefaultLanguage;

                        extractor.SourceFiles = new SourceFileList(
                            extractOptions.RootDirectory,
                            extractOptions.Extensions,
                            extractOptions.ExcludePatterns).GetFiles();

                        var target = new XmlTextSource();
                        target.Put(extractor.Get().Select(x =>
                                                          new LocalizedTextState {
                            Text = x, Status = LocalizedTextStatus.New
                        }), TextMergeOptions.KeepUnused);

                        target.Document.Save(extractOptions.TargetFile);

                        return;
                    }
                }
                else if (args[0] == "compare")
                {
                    if (parser.ParseArguments(args, compareOptions))
                    {
                        Console.WriteLine();

                        var texts = new TextSourceAggregator();
                        using (texts.BeginUpdate())
                        {
                            foreach (var file in compareOptions.Files)
                            {
                                texts.Sources.Add(new PrioritizedTextSource(new XmlTextSource(XDocument.Load(file)), 1));
                            }
                        }


                        var comparer = new LanguageComparer(texts);
                        var result   = comparer.Compare(
                            compareOptions.SourceLanguage,
                            compareOptions.TargetLanguage);

                        Console.WriteLine(result.Success ?
                                          "OK - The text(s) defines the same keys for the languages" :
                                          "The two languages differ");
                        Console.Out.WriteLine();
                        foreach (var text in result.MissingTexts)
                        {
                            Console.Out.WriteLine("Missing\t" + text.Key);
                        }
                        foreach (var text in result.UnmatchedTexts)
                        {
                            Console.Out.WriteLine("Unmatched\t" + text.Key);
                        }
                        return;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine("Usage: ");
            Console.WriteLine();
            Console.WriteLine("Localization.exe extract");
            WriteHelp(extractOptions);
            Console.WriteLine();
            Console.WriteLine("Localization.exe compare");
            WriteHelp(compareOptions);
            Console.WriteLine();
        }