1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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