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.*;
23 import java.util.*;
24
25 public class SyncKeys {
26
27 /***
28 *
29 */
30 public static void main(String[] argv)
31 {
32 if (argv.length < 2) {
33 System.err.println("usage: SyncKeys syncfile file [file...]");
34 System.exit(1);
35 }
36
37 Hashtable table = null;
38 try {
39 System.out.println("Using Sync table: " + argv[0]);
40 table = I18nHelper.readI18nFile(argv[0], true);
41 }
42 catch (IOException e) {
43 System.err.println("Error: " + e.getMessage());
44 System.exit(1);
45 }
46
47 for (int i = 1; i < argv.length; i++) {
48 try {
49 System.out.println("Syncing keys in file: " + argv[i]);
50 sync(argv[i], table);
51 }
52 catch (IOException e) {
53 System.err.println("Error: " + e.getMessage());
54 }
55 }
56 }
57
58 public static void sync(String filename, Hashtable table)
59 throws IOException
60 {
61 Hashtable fileTable = I18nHelper.readI18nFile(filename, false);
62
63 for (Iterator i = table.keySet().iterator(); i.hasNext();) {
64 String oldKey = (String)i.next();
65 String newKey = (String)table.get(oldKey);
66
67 if (!oldKey.equals(newKey)) {
68 String value = (String)fileTable.get(oldKey);
69 if (value != null) {
70 System.out.println(oldKey + " -> " + newKey + " = "
71 + value);
72 fileTable.remove(oldKey);
73 fileTable.put(newKey, value);
74 }
75 }
76 }
77
78 I18nHelper.writeI18nFile(filename, fileTable);
79 }
80
81 }
82
83