27 |
27 |
import org.apache.commons.io.FilenameUtils;
|
28 |
28 |
import org.apache.commons.lang.StringUtils;
|
29 |
29 |
import org.eclipse.osgi.util.NLS;
|
|
30 |
import org.txm.rcp.translate.devtools.NormalizeKeys;
|
30 |
31 |
import org.txm.utils.BiHashMap;
|
31 |
32 |
import org.txm.utils.io.IOUtils;
|
32 |
33 |
|
... | ... | |
528 |
529 |
TreeSet<String> oldKeys = new TreeSet<String>(IOUtils.findWithGroup(javaMessageFile, "public static String ([^\"=;]+);"));
|
529 |
530 |
TreeSet<String> newKeys = new TreeSet<String>(messageKeys);
|
530 |
531 |
newKeys.removeAll(oldKeys);
|
531 |
|
System.out.println("OLD1="+oldKeys);
|
532 |
|
System.out.println("NEW1="+newKeys);
|
533 |
|
newKeys.removeAll(keyModifications.values());
|
534 |
|
System.out.println("NEW2="+newKeys);
|
|
532 |
newKeys.removeAll(keyModifications.values()); // now contains only the very newly created keys
|
|
533 |
|
535 |
534 |
if (replaceFiles) {
|
536 |
535 |
newJavaMessageFile = javaMessageFile;
|
537 |
536 |
}
|
538 |
537 |
|
539 |
|
String className = getMessageClassName();
|
540 |
|
String name = getMessageName();
|
541 |
|
String classPackage = getMessageFullClassName().substring(0, getMessageFullClassName().length() - getMessageClassName().length() - 1);
|
542 |
|
|
543 |
|
// PrintWriter out = IOUtils.getWriter(newJavaMessageFile, ENCODING);
|
544 |
|
//
|
545 |
|
// // update lines
|
546 |
|
// for (String line : lines) {
|
547 |
|
// String l = line.trim();// remove tabs
|
548 |
|
// String comments = "";
|
549 |
|
// int idx = l.indexOf("//"); // remove comments
|
550 |
|
// if (idx > 0) {
|
551 |
|
// comments = l.substring(idx).trim();
|
552 |
|
// l = l.substring(0, idx).trim();
|
553 |
|
// }
|
554 |
|
//
|
555 |
|
// if (l.startsWith("private static final String BUNDLE_NAME")) {
|
556 |
|
// out.println(line);
|
557 |
|
//
|
558 |
|
// // write the totally new keys
|
559 |
|
// } else if (l.startsWith("public static String") && l.endsWith(";") && !l.contains("=") && !l.contains("\"")) {
|
560 |
|
//
|
561 |
|
// String key = l.substring(21, l.length() -1);
|
562 |
|
// if (messageKeys.contains(key)) {
|
563 |
|
// out.println(line); // keep the line
|
564 |
|
// } else if (keyModifications.containsKey(key)){
|
565 |
|
// // the key has been renamed
|
566 |
|
// out.println("\t\tpublic static String "+keyModifications.get(key)+"; "+comments);
|
567 |
|
// } else {
|
568 |
|
// // the key has been removed
|
569 |
|
// }
|
570 |
|
// } else {
|
571 |
|
// out.println(line);
|
572 |
|
// }
|
573 |
|
// }
|
574 |
|
//
|
575 |
|
// out.close();
|
|
538 |
PrintWriter out = IOUtils.getWriter(newJavaMessageFile, ENCODING);
|
|
539 |
|
|
540 |
// update lines
|
|
541 |
for (String line : lines) {
|
|
542 |
String l = line.trim();// remove tabs
|
|
543 |
String comments = "";
|
|
544 |
int idx = l.indexOf("//"); // remove comments
|
|
545 |
if (idx > 0) {
|
|
546 |
comments = l.substring(idx).trim();
|
|
547 |
l = l.substring(0, idx).trim();
|
|
548 |
}
|
|
549 |
|
|
550 |
if (l.startsWith("private static final String BUNDLE_NAME")) {
|
|
551 |
out.println(line);
|
|
552 |
|
|
553 |
// write the totally new keys
|
|
554 |
if (newKeys.size() > 0) {
|
|
555 |
out.println("\t");
|
|
556 |
}
|
|
557 |
for (String key : newKeys) {
|
|
558 |
out.println("\tpublic static String "+key+";");
|
|
559 |
}
|
|
560 |
} else if (l.startsWith("public static String") && l.endsWith(";") && !l.contains("=") && !l.contains("\"")) {
|
|
561 |
|
|
562 |
String key = l.substring(21, l.length() -1);
|
|
563 |
if (messageKeys.contains(key)) {
|
|
564 |
out.println(line); // keep the line
|
|
565 |
} else if (keyModifications.containsKey(key)){
|
|
566 |
// the key has been renamed
|
|
567 |
out.println("\tpublic static String "+keyModifications.get(key)+"; "+comments);
|
|
568 |
} else {
|
|
569 |
// the key has been removed
|
|
570 |
}
|
|
571 |
} else {
|
|
572 |
out.println(line);
|
|
573 |
}
|
|
574 |
}
|
|
575 |
|
|
576 |
out.close();
|
576 |
577 |
}
|
577 |
578 |
|
578 |
579 |
public void summary() {
|
... | ... | |
793 |
794 |
*/
|
794 |
795 |
//dict.summary();
|
795 |
796 |
|
|
797 |
pmManager.saveChanges(false);
|
796 |
798 |
|
797 |
|
pmManager.saveChanges(true);
|
798 |
|
|
|
799 |
System.out.println("dir="+pmManager.getProjectDirectory());
|
799 |
800 |
System.out.println("PluginMessagesManager.main(): done.");
|
800 |
801 |
}
|
|
802 |
|
|
803 |
private void newKey(String defaultMessage) {
|
|
804 |
String key = NormalizeKeys.normalize(defaultMessage);
|
|
805 |
String newKey = ""+key;
|
|
806 |
int c = 1;
|
|
807 |
while (messageKeys.contains(newKey)) {
|
|
808 |
newKey = key+"_"+(c++);
|
|
809 |
}
|
|
810 |
|
|
811 |
messageKeys.add(newKey);
|
|
812 |
getMessagesForDefaultLang().put(newKey, defaultMessage);
|
|
813 |
}
|
801 |
814 |
}
|