View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.i18n;
21  
22  import java.io.File;
23  import java.io.FileOutputStream;
24  import java.io.IOException;
25  import java.util.HashSet;
26  import java.util.Hashtable;
27  import java.util.Iterator;
28  import java.util.Properties;
29  
30  public class I18nToResource {
31  
32      /***
33       * 
34       */
35      public static void main(String[] argv)
36      {
37  	if (argv.length != 2) {
38  	    System.err.println("usage: I18nToResource i18nfile resourcefile");
39  	    System.exit(1);
40  
41  	}
42  
43  	HashSet keys = I18nHelper.readKeys();
44  
45  	try {
46  	    System.out.println(argv[0] + " -> " + argv[1]);
47  	    write(argv[0], argv[1], keys);
48  	}
49  	catch (IOException e) {
50  	    System.err.println("Error: " + e.getMessage());
51  	    System.exit(1);
52  	}
53      }
54  
55      public static void write(String source, String dest, HashSet keys)
56  	throws IOException
57      {
58  	Hashtable table = I18nHelper.readI18nFile(source, true);
59  
60  	Properties props = new Properties();
61  	for (Iterator i = table.keySet().iterator(); i.hasNext();) {
62  	    String key = (String)i.next();
63  	    if (keys.contains(key)) {
64  		String value = I18nHelper.rawToJava(table.get(key).toString());
65  		key = I18nHelper.rawToJava(key);
66  		props.put(key, value);
67  	    }
68  	}
69  
70  	FileOutputStream out = new FileOutputStream(new File(dest));
71  	props.store(out, "Generated by I18nToResource. Don't edit manually. "
72  		    + "Use files in i18n directory instead.");
73  	out.close();
74      }
75  
76  }
77  
78