Révision 1291
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/RemoveUnusedTranslations.java (revision 1291) | ||
---|---|---|
5 | 5 |
import java.io.IOException; |
6 | 6 |
import java.io.UnsupportedEncodingException; |
7 | 7 |
import java.util.ArrayList; |
8 |
import java.util.HashMap; |
|
8 | 9 |
import java.util.LinkedHashMap; |
9 | 10 |
import java.util.LinkedHashSet; |
10 | 11 |
import java.util.TreeSet; |
... | ... | |
29 | 30 |
|
30 | 31 |
int n = 0; |
31 | 32 |
|
32 |
BiHashMap<String, String> lmessages = messages.getMessagesForLang(lang);
|
|
33 |
HashMap<String, String> lmessages = messages.getMessagesForLang(lang); |
|
33 | 34 |
if (lmessages == null) continue; |
34 | 35 |
|
35 |
ArrayList<String> propskeys = new ArrayList<String>(lmessages.getKeys());
|
|
36 |
ArrayList<String> propskeys = new ArrayList<String>(lmessages.keySet());
|
|
36 | 37 |
ArrayList<String> removed = new ArrayList<String>(); |
37 | 38 |
|
38 | 39 |
for (String k : propskeys) { |
39 | 40 |
if (!keys.contains(k)) { |
40 | 41 |
//System.out.println(" Remove key="+k); |
41 |
lmessages.removeByKey(k);
|
|
42 |
lmessages.remove(k); |
|
42 | 43 |
removed.add(k); |
43 | 44 |
n++; |
44 | 45 |
} |
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ExportToOneFile.java (revision 1291) | ||
---|---|---|
44 | 44 |
for (String lang : langs) { |
45 | 45 |
File propFile = messages.getFile2lang().getKey(lang); |
46 | 46 |
if (propFile != null) { |
47 |
BiHashMap<String, String> lmessages = messages.getLangs().get(propFile);
|
|
47 |
HashMap<String, String> lmessages = messages.getLangs().get(propFile); |
|
48 | 48 |
for (String key : messages.getMessageKeys()) { |
49 | 49 |
|
50 | 50 |
if (lmessages.get(key) == null) continue; |
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1291) | ||
---|---|---|
4 | 4 |
import java.io.IOException; |
5 | 5 |
import java.io.UnsupportedEncodingException; |
6 | 6 |
import java.util.ArrayList; |
7 |
import java.util.HashMap; |
|
7 | 8 |
|
8 | 9 |
import org.txm.rcp.translate.i18n.PluginMessagesManager; |
9 | 10 |
import org.txm.rcp.translate.i18n.WorkspaceMessagesManager; |
... | ... | |
47 | 48 |
*/ |
48 | 49 |
public int normalize(PluginMessagesManager pmManager) { |
49 | 50 |
|
50 |
BiHashMap<String, String> messages = pmManager.getMessagesForDefaultLang();
|
|
51 |
HashMap<String, String> messages = pmManager.getMessagesForDefaultLang(); |
|
51 | 52 |
|
52 | 53 |
ArrayList<String> keys = new ArrayList<String>(pmManager.getMessageKeys()); |
53 | 54 |
|
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/MergeDuplicatedStringsInAPlugin.java (revision 1291) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.translate.devtools; |
2 | 2 |
|
3 |
import java.io.FileNotFoundException; |
|
4 |
import java.io.IOException; |
|
5 |
import java.io.UnsupportedEncodingException; |
|
6 |
|
|
7 |
import org.txm.rcp.translate.i18n.PluginMessagesManager; |
|
8 |
import org.txm.rcp.translate.i18n.WorkspaceMessagesManager; |
|
9 |
|
|
3 | 10 |
/** |
4 | 11 |
* |
5 | 12 |
* Finds duplicated strings in a plug-in, merge them in one key and remove duplicated. |
6 | 13 |
* |
7 | 14 |
*/ |
8 | 15 |
public class MergeDuplicatedStringsInAPlugin { |
16 |
|
|
17 |
boolean debug = false; |
|
18 |
|
|
19 |
/** |
|
20 |
* |
|
21 |
* @param debug |
|
22 |
*/ |
|
23 |
public MergeDuplicatedStringsInAPlugin(boolean debug) { |
|
24 |
this.debug = debug; |
|
25 |
} |
|
9 | 26 |
|
27 |
public void merge(PluginMessagesManager pm) { |
|
28 |
// TODO Auto-generated method stub |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
* @param args |
|
34 |
* @throws IOException |
|
35 |
* @throws FileNotFoundException |
|
36 |
* @throws UnsupportedEncodingException |
|
37 |
*/ |
|
38 |
public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException { |
|
39 |
|
|
40 |
MergeDuplicatedStringsInAPlugin merger = new MergeDuplicatedStringsInAPlugin(false); |
|
41 |
|
|
42 |
WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(); |
|
43 |
for (PluginMessagesManager pm : wmm.getPluginMessages().values()) { |
|
44 |
merger.merge(pm); |
|
45 |
|
|
46 |
//pm.saveChanges(true); |
|
47 |
} |
|
48 |
|
|
49 |
//wmm.saveKeyModificationsInSources(); |
|
50 |
} |
|
10 | 51 |
} |
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessagesManager.java (revision 1291) | ||
---|---|---|
99 | 99 |
return osgiKeys; |
100 | 100 |
} |
101 | 101 |
|
102 |
public TreeMap<File, BiHashMap<String, String>> getOsgiLangs() {
|
|
102 |
public TreeMap<File, HashMap<String, String>> getOsgiLangs() { |
|
103 | 103 |
return osgiLangs; |
104 | 104 |
} |
105 | 105 |
|
... | ... | |
111 | 111 |
/** |
112 | 112 |
* The OSGI messages stored by properties file |
113 | 113 |
*/ |
114 |
TreeMap<File, BiHashMap<String, String>> osgiLangs = new TreeMap<File, BiHashMap<String, String>>();
|
|
114 |
TreeMap<File, HashMap<String, String>> osgiLangs = new TreeMap<File, HashMap<String, String>>();
|
|
115 | 115 |
|
116 | 116 |
/** |
117 | 117 |
* Stores the key modifications for further saves in the source files |
... | ... | |
121 | 121 |
/** |
122 | 122 |
* The messages stored by properties file |
123 | 123 |
*/ |
124 |
TreeMap<File, BiHashMap<String, String>> langs = new TreeMap<File, BiHashMap<String, String>>();
|
|
124 |
TreeMap<File, HashMap<String, String>> langs = new TreeMap<File, HashMap<String, String>>();
|
|
125 | 125 |
|
126 | 126 |
/** |
127 | 127 |
* the properties files langs |
... | ... | |
207 | 207 |
//messages.properties |
208 | 208 |
//messages_xx.properties |
209 | 209 |
String lang = name.substring(8, name.indexOf(".properties")); |
210 |
langs.put(propFile, new BiHashMap<String, String>());
|
|
210 |
langs.put(propFile, new HashMap<String, String>()); |
|
211 | 211 |
file2lang.put(propFile, lang); |
212 | 212 |
|
213 |
BiHashMap<String, String> hash = langs.get(propFile);
|
|
213 |
HashMap<String, String> hash = langs.get(propFile); |
|
214 | 214 |
|
215 | 215 |
Properties props1 = new Properties(); |
216 | 216 |
props1.load(IOUtils.getReader(propFile, ENCODING)); |
... | ... | |
258 | 258 |
if (propFile.getName().startsWith("bundle") && propFile.getName().endsWith(".properties")) { |
259 | 259 |
Properties props = new Properties(); |
260 | 260 |
props.load(IOUtils.getReader(propFile)); |
261 |
osgiLangs.put(propFile, new BiHashMap<String, String>(props)); |
|
261 |
HashMap<String, String> h = new HashMap<String, String>(); |
|
262 |
for (Object k : props.keySet()) h.put(k.toString(), props.getProperty(k.toString())); |
|
263 |
osgiLangs.put(propFile, h); |
|
262 | 264 |
} |
263 | 265 |
} |
264 | 266 |
} |
... | ... | |
403 | 405 |
* @param lang |
404 | 406 |
* @return the map of the messages keys and values for the specified language. |
405 | 407 |
*/ |
406 |
public BiHashMap<String, String> getMessagesForLang(String lang) {
|
|
408 |
public HashMap<String, String> getMessagesForLang(String lang) { |
|
407 | 409 |
if (javaMessageFile != null) { |
408 | 410 |
File p = new File(javaMessageFile.getParentFile(), "messages" + lang + ".properties"); |
409 | 411 |
return langs.get(p); |
410 | 412 |
} else { |
411 |
return new BiHashMap<String, String>();
|
|
413 |
return new HashMap<String, String>(); |
|
412 | 414 |
} |
413 | 415 |
} |
414 | 416 |
|
415 | 417 |
/** |
416 | 418 |
* @return the map of the messages keys and values for the main language. |
417 | 419 |
*/ |
418 |
public BiHashMap<String, String> getMessagesForDefaultLang() {
|
|
420 |
public HashMap<String, String> getMessagesForDefaultLang() { |
|
419 | 421 |
return this.getMessagesForLang(""); //$NON-NLS-1$ |
420 | 422 |
} |
421 | 423 |
|
... | ... | |
425 | 427 |
File p = new File(javaMessageFile.getParentFile(), "messages"+lang+".properties"); |
426 | 428 |
|
427 | 429 |
if (!langs.containsKey(p)) { |
428 |
langs.put(p, new BiHashMap<String, String>());
|
|
430 |
langs.put(p, new HashMap<String, String>()); |
|
429 | 431 |
file2lang.put(p, lang); |
430 | 432 |
} |
431 | 433 |
|
432 | 434 |
if (message == null) { |
433 |
langs.get(p).removeByKey(key);
|
|
435 |
langs.get(p).remove(key); |
|
434 | 436 |
} else { |
435 | 437 |
langs.get(p).put(key, message); |
436 | 438 |
} |
... | ... | |
509 | 511 |
return Collections.enumeration(set); |
510 | 512 |
} |
511 | 513 |
}; |
512 |
BiHashMap<String, String> h = langs.get(propFile);
|
|
513 |
for (String k : h.getKeys()) {
|
|
514 |
HashMap<String, String> h = langs.get(propFile); |
|
515 |
for (String k : h.keySet()) {
|
|
514 | 516 |
props.setProperty(k, h.get(k)); |
515 | 517 |
} |
516 | 518 |
|
... | ... | |
590 | 592 |
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------"); |
591 | 593 |
System.out.println(" " + lang); |
592 | 594 |
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------"); |
593 |
BiHashMap<String, String> hash = langs.get(lang);
|
|
594 |
System.out.println(" keys="+ hash.getKeys());
|
|
595 |
for (String key : hash.getKeys()) {
|
|
595 |
HashMap<String, String> hash = langs.get(lang); |
|
596 |
System.out.println(" keys="+ hash.keySet());
|
|
597 |
for (String key : hash.keySet()) {
|
|
596 | 598 |
System.out.println(" " + key + "="+hash.get(key)); |
597 | 599 |
} |
598 | 600 |
} |
... | ... | |
672 | 674 |
messageKeys.add(newName); |
673 | 675 |
|
674 | 676 |
for (File p : langs.keySet()) { |
675 |
BiHashMap<String, String> h = langs.get(p);
|
|
677 |
HashMap<String, String> h = langs.get(p); |
|
676 | 678 |
if (h.containsKey(oldName)) { |
677 | 679 |
h.put(newName, h.get(oldName)); |
678 |
h.removeByKey(oldName);
|
|
680 |
h.remove(oldName); |
|
679 | 681 |
} |
680 | 682 |
} |
681 | 683 |
|
... | ... | |
696 | 698 |
messageKeys.remove(key); |
697 | 699 |
|
698 | 700 |
for (File p : langs.keySet()) { |
699 |
BiHashMap<String, String> h = langs.get(p);
|
|
701 |
HashMap<String, String> h = langs.get(p); |
|
700 | 702 |
if (h.containsKey(key)) { |
701 |
h.removeByKey(key);
|
|
703 |
h.remove(key); |
|
702 | 704 |
} |
703 | 705 |
} |
704 | 706 |
|
... | ... | |
717 | 719 |
return file2lang; |
718 | 720 |
} |
719 | 721 |
|
720 |
public TreeMap<File, BiHashMap<String, String>> getLangs() {
|
|
722 |
public TreeMap<File, HashMap<String, String>> getLangs() { |
|
721 | 723 |
return langs; |
722 | 724 |
} |
723 | 725 |
|
Formats disponibles : Unified diff