Révision 1278
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/RemoveUnusedKeys.java (revision 1278) | ||
---|---|---|
42 | 42 |
|
43 | 43 |
if (n > 0) { |
44 | 44 |
System.out.println(pm.getMessageFullName()+" "+n+" key removed: "+removedKeys); |
45 |
//pm.saveChanges(true);
|
|
45 |
pm.saveChanges(true); |
|
46 | 46 |
total += n; |
47 | 47 |
} |
48 | 48 |
} |
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/RemoveUnusedTranslations.java (revision 1278) | ||
---|---|---|
4 | 4 |
import java.io.FileNotFoundException; |
5 | 5 |
import java.io.IOException; |
6 | 6 |
import java.io.UnsupportedEncodingException; |
7 |
import java.util.ArrayList; |
|
7 | 8 |
import java.util.LinkedHashMap; |
8 | 9 |
import java.util.LinkedHashSet; |
9 | 10 |
import java.util.TreeSet; |
... | ... | |
18 | 19 |
LinkedHashMap<File, PluginMessagesManager> h = wmm.getPluginMessages(); |
19 | 20 |
|
20 | 21 |
String langs[] = {"", "_fr", "_ru"}; |
21 |
|
|
22 |
int total = 0; |
|
22 | 23 |
for (File project : h.keySet()) { |
23 | 24 |
|
24 | 25 |
PluginMessagesManager messages = h.get(project); |
25 | 26 |
TreeSet<String> keys = messages.getMessageKeys(); |
27 |
|
|
26 | 28 |
for (String lang : langs) { |
29 |
|
|
30 |
int n = 0; |
|
31 |
|
|
27 | 32 |
BiHashMap<String, String> lmessages = messages.getMessagesForLang(lang); |
28 | 33 |
if (lmessages == null) continue; |
29 | 34 |
|
30 |
for (String k : lmessages.getKeys()) { |
|
35 |
ArrayList<String> propskeys = new ArrayList<String>(lmessages.getKeys()); |
|
36 |
ArrayList<String> removed = new ArrayList<String>(); |
|
37 |
|
|
38 |
for (String k : propskeys) { |
|
31 | 39 |
if (!keys.contains(k)) { |
32 |
System.out.println(" Remove key="+k); |
|
40 |
//System.out.println(" Remove key="+k);
|
|
33 | 41 |
lmessages.removeByKey(k); |
42 |
removed.add(k); |
|
43 |
n++; |
|
34 | 44 |
} |
35 | 45 |
} |
46 |
|
|
47 |
if (n > 0) { |
|
48 |
System.out.println(messages.getMessageFullClassName()+" "+n+" "+lang+" keys removed: "+removed); |
|
49 |
//System.out.println("all keys:" + keys); |
|
50 |
messages.saveChanges(true); |
|
51 |
total += n; |
|
52 |
} |
|
36 | 53 |
} |
37 |
|
|
38 |
// messages.saveChanges(); |
|
39 | 54 |
} |
55 |
|
|
56 |
if (total > 0) { |
|
57 |
System.out.println("Done: "+total+" keys removed."); |
|
58 |
} else { |
|
59 |
System.out.println("Done: no change."); |
|
60 |
} |
|
40 | 61 |
} |
41 | 62 |
} |
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessagesManager.java (revision 1278) | ||
---|---|---|
195 | 195 |
System.out.println("PluginMessages.PluginMessages(): project root directory = " + this.projectDirectory); |
196 | 196 |
System.out.println("PluginMessages.PluginMessages(): java message file = " + this.javaMessageFile); |
197 | 197 |
} |
198 |
|
|
199 | 198 |
|
199 |
|
|
200 | 200 |
if (this.javaMessageFile != null) { |
201 |
|
|
201 |
|
|
202 | 202 |
File[] propFiles = javaMessageFile.getParentFile().listFiles(); |
203 | 203 |
for (File propFile : propFiles) { |
204 | 204 |
String name = propFile.getName(); |
... | ... | |
217 | 217 |
hash.put(k.toString(), props1.get(k).toString()); |
218 | 218 |
} |
219 | 219 |
} |
220 |
|
|
220 |
|
|
221 | 221 |
BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(javaMessageFile), ENCODING)); |
222 | 222 |
String line2 = reader2.readLine(); |
223 | 223 |
while (line2 != null) { |
224 | 224 |
line2 = line2.trim(); |
225 |
if (line2.startsWith("public static String") && line2.endsWith(";") && !line2.contains("=")) { |
|
225 |
int idx = line2.indexOf("//"); |
|
226 |
if (idx > 0) { // remove comment from line |
|
227 |
System.out.println("COMMENT DETECTED AFTER KEY: line="+line2+" IN "+javaMessageFile); |
|
228 |
line2 = line2.substring(0, idx).trim(); |
|
229 |
} |
|
230 |
if (line2.startsWith("public static String") && line2.endsWith(";") && !line2.contains("=") && !line2.contains("\"")) { |
|
226 | 231 |
line2 = line2.substring(21, line2.length() -1); |
227 | 232 |
messageKeys.add(line2); |
233 |
|
|
234 |
if (idx > 0) { // FIXME show warning since comment is lost |
|
235 |
|
|
236 |
} |
|
228 | 237 |
} |
238 |
|
|
229 | 239 |
line2 = reader2.readLine(); |
230 | 240 |
} |
231 | 241 |
reader2.close(); |
... | ... | |
252 | 262 |
} |
253 | 263 |
} |
254 | 264 |
} |
255 |
// System.out.println(osgiKeys); |
|
256 |
// System.out.println(osgiLangs); |
|
265 |
// System.out.println(osgiKeys);
|
|
266 |
// System.out.println(osgiLangs);
|
|
257 | 267 |
} |
258 | 268 |
|
259 | 269 |
if(debug) { |
... | ... | |
394 | 404 |
* @return the map of the messages keys and values for the specified language. |
395 | 405 |
*/ |
396 | 406 |
public BiHashMap<String, String> getMessagesForLang(String lang) { |
397 |
File p = new File(javaMessageFile.getParentFile(), "messages" + lang + ".properties"); |
|
398 |
return langs.get(p); |
|
407 |
if (javaMessageFile != null) { |
|
408 |
File p = new File(javaMessageFile.getParentFile(), "messages" + lang + ".properties"); |
|
409 |
return langs.get(p); |
|
410 |
} else { |
|
411 |
return new BiHashMap<String, String>(); |
|
412 |
} |
|
399 | 413 |
} |
400 | 414 |
|
401 | 415 |
/** |
... | ... | |
405 | 419 |
return this.getMessagesForLang(""); //$NON-NLS-1$ |
406 | 420 |
} |
407 | 421 |
|
408 |
|
|
409 | 422 |
public void put(String lang, String key, String message) { |
410 | 423 |
messageKeys.add(key); |
411 | 424 |
|
... | ... | |
480 | 493 |
public void saveChanges(boolean replaceFiles) throws IOException { |
481 | 494 |
|
482 | 495 |
if (javaMessageFile == null) return; |
483 |
|
|
496 |
|
|
484 | 497 |
//Write prop File |
485 | 498 |
for (File propFile : langs.keySet()) { |
486 | 499 |
|
Formats disponibles : Unified diff