File: AddinXmlStringExtractor.cs

package info (click to toggle)
hyena 0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,800 kB
  • sloc: cs: 33,411; sh: 733; makefile: 435
file content (47 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Xml.XPath;
using System.Collections.Generic;

public static class AddinXmlStringExtract
{
    public static void Main (string [] args)
    {
        var queries = new [] {
            "/Addin/@name",
            "/Addin/@description",
            "/Addin/@category"
        };

        Console.WriteLine (@"// Generated - Do Not Edit!

internal static class AddinXmlStringCatalog
{
    private static void Strings ()
    {");

        var paths = new List<string> (args);
        paths.Sort ();

        foreach (var path in paths) {
            Console.WriteLine ("        // {0}", path);
            var xpath = new XPathDocument (path);
            var nav = xpath.CreateNavigator ();
            foreach (var query in queries) {
                var iter = nav.Select (query);
                while (iter.MoveNext ()) {
                    var value = iter.Current.Value.Trim ();
                    if (String.IsNullOrEmpty (value) ||
                        value[0] == '@' ||
                        (iter.Current.Name == "category" && value.StartsWith ("required:"))) {
                        continue;
                    }
                    Console.WriteLine (@"        Catalog.GetString (@""{0}"");",
                        value.Replace (@"""", @""""""));
                }
            }
            Console.WriteLine ();
        }

        Console.WriteLine ("    }\n}");
    }
}