~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Tools/LocalizationXmlToResFile/LocalizationXmlToResFile.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="" email=""/>
 
5
//     <version>$Revision$</version>
 
6
// </file>
 
7
 
 
8
using System;
 
9
using System.Collections;
 
10
using System.Drawing;
 
11
using System.Resources;
 
12
using System.IO;
 
13
using System.Text;
 
14
using System.Drawing.Imaging;
 
15
using System.Windows.Forms;
 
16
using System.Runtime.Serialization.Formatters.Binary;
 
17
using System.Xml;
 
18
 
 
19
public class TranslationBuilder
 
20
{
 
21
        static void Assemble(string pattern)
 
22
        {
 
23
                string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), pattern);
 
24
                
 
25
                foreach (string file in files) {
 
26
                        if (Path.GetExtension(file).ToUpper() == ".XML") {
 
27
                                try {
 
28
                                        XmlDocument  doc = new XmlDocument();
 
29
                                        doc.Load(file);
 
30
                                        string resfilename = "StringResources." + doc.DocumentElement.Attributes["language"].InnerText + ".resources";
 
31
                                        ResourceWriter  rw = new ResourceWriter(resfilename);
 
32
                                        
 
33
                                        foreach (XmlElement el in doc.DocumentElement.ChildNodes) {
 
34
                                                rw.AddResource(el.Attributes["name"].InnerText, 
 
35
                                                               el.InnerText);
 
36
                                        }
 
37
                                        
 
38
                                        rw.Generate();
 
39
                                        rw.Close();
 
40
                                } catch (Exception e) {
 
41
                                        Console.WriteLine("Error while processing " + file + " :");
 
42
                                        Console.WriteLine(e.ToString());
 
43
                                }
 
44
                        }
 
45
                }
 
46
        }
 
47
        
 
48
        static void ShowHelp()
 
49
        {
 
50
                Console.WriteLine(".NET Translation Builder Version 0.1");
 
51
                Console.WriteLine("Copyright (C) Mike Krueger 2001. Released under GPL.\n");
 
52
                Console.WriteLine("                      Translation Builder Options Options\n");
 
53
                Console.WriteLine("                        - INPUT FILES -");
 
54
                Console.WriteLine("<wildcard>              translates the given xml files into resource files");
 
55
        }
 
56
        
 
57
        public static void Main(string[] args)
 
58
        {
 
59
                if (args.Length == 0) {
 
60
                        ShowHelp();
 
61
                }
 
62
                foreach (string param in args) {
 
63
                        string par = param.ToUpper();
 
64
                        if (par == "/?" || par == "/H" || par== "-?" || par == "-H" || par == "?") {
 
65
                                ShowHelp();
 
66
                                return;
 
67
                        } else {
 
68
                                Assemble(param);
 
69
                        }
 
70
                }
 
71
        }
 
72
}