Révision 1289
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessagesManager.java (revision 1289) | ||
---|---|---|
192 | 192 |
|
193 | 193 |
if (debug) { |
194 | 194 |
System.out.println("********************************************************************************************************************"); |
195 |
System.out.println("PluginMessages.PluginMessages(): project root directory = " + this.projectDirectory); |
|
196 |
System.out.println("PluginMessages.PluginMessages(): java message file = " + this.javaMessageFile); |
|
195 |
System.out.println("PluginMessagesManager.PluginMessages(): project root directory = " + this.projectDirectory);
|
|
196 |
System.out.println("PluginMessagesManager.PluginMessages(): java message file = " + this.javaMessageFile);
|
|
197 | 197 |
} |
198 | 198 |
|
199 | 199 |
|
... | ... | |
285 | 285 |
// this.keysGlobalREGEX = Pattern.compile("(" + buffer + ")"); |
286 | 286 |
// |
287 | 287 |
// if(debug) { |
288 |
// System.out.println("PluginMessages.createKeysGlobalREGEX(): REGEX created: " + this.keysGlobalREGEX + "."); |
|
288 |
// System.out.println("PluginMessagesManager.createKeysGlobalREGEX(): REGEX created: " + this.keysGlobalREGEX + ".");
|
|
289 | 289 |
// } |
290 | 290 |
// |
291 | 291 |
// } |
... | ... | |
300 | 300 |
//for (String key : messageKeys) { |
301 | 301 |
|
302 | 302 |
// if(debug) { |
303 |
// System.out.println("PluginMessages.createUsedKeysIndex(): looking for key " + this.getKeyFullName(key) + " in project source files..."); |
|
303 |
// System.out.println("PluginMessagesManager.createUsedKeysIndex(): looking for key " + this.getKeyFullName(key) + " in project source files...");
|
|
304 | 304 |
// } |
305 | 305 |
|
306 | 306 |
for (File file : this.srcFiles) { |
... | ... | |
332 | 332 |
*/ |
333 | 333 |
public void dumpUsedKeysFilesIndex() { |
334 | 334 |
|
335 |
System.out.println("PluginMessages.dumpUsedKeysIndex(): dumping used keys files index..."); |
|
335 |
System.out.println("PluginMessagesManager.dumpUsedKeysIndex(): dumping used keys files index...");
|
|
336 | 336 |
|
337 | 337 |
for (Map.Entry<String, TreeSet<File>> entry : this.usedKeysFilesIndex.entrySet()) { |
338 | 338 |
System.out.println("key: " + this.getKeyFullName(entry.getKey())); |
... | ... | |
387 | 387 |
if(entry.getValue().isEmpty()) { |
388 | 388 |
|
389 | 389 |
if(debug) { |
390 |
System.out.println("PluginMessages.getUnusedKeys(): unused key found: " + entry.getKey() + "."); |
|
390 |
System.out.println("PluginMessagesManager.getUnusedKeys(): unused key found: " + entry.getKey() + ".");
|
|
391 | 391 |
} |
392 | 392 |
|
393 | 393 |
unusedKeys.add(entry.getKey()); |
... | ... | |
523 | 523 |
|
524 | 524 |
// write message File |
525 | 525 |
File newJavaMessageFile = new File(javaMessageFile.getParentFile(), javaMessageFile.getName()+".new"); |
526 |
|
|
527 |
ArrayList<String> lines = IOUtils.getLines(javaMessageFile, "UFT-8"); |
|
528 |
TreeSet<String> oldKeys = new TreeSet<String>(IOUtils.findWithGroup(javaMessageFile, "public static String ([^\"=;]+);")); |
|
529 |
TreeSet<String> newKeys = new TreeSet<String>(messageKeys); |
|
530 |
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); |
|
526 | 535 |
if (replaceFiles) { |
527 |
javaMessageFile.delete(); |
|
528 | 536 |
newJavaMessageFile = javaMessageFile; |
529 | 537 |
} |
530 | 538 |
|
... | ... | |
532 | 540 |
String name = getMessageName(); |
533 | 541 |
String classPackage = getMessageFullClassName().substring(0, getMessageFullClassName().length() - getMessageClassName().length() - 1); |
534 | 542 |
|
535 |
PrintWriter out = IOUtils.getWriter(newJavaMessageFile, ENCODING); |
|
536 |
|
|
537 |
// write start |
|
538 |
out.println("package "+classPackage+";\n"); |
|
539 |
|
|
540 |
out.println("import org.eclipse.osgi.util.NLS;"); |
|
541 |
out.println("import org.txm.utils.messages.Utf8NLS;\n"); |
|
542 |
|
|
543 |
out.println("/**\n * "+name+" messages.\n * @author sjacquot, mdecorde \n */"); |
|
544 |
|
|
545 |
out.println("public class "+className+" extends NLS {\n"); |
|
546 |
|
|
547 |
out.println(" private static final String BUNDLE_NAME = \""+classPackage+".messages\"; //$NON-NLS-1$\n"); |
|
548 |
|
|
549 |
//write keys |
|
550 |
ArrayList<String> keys = new ArrayList<String>(this.getMessageKeys()); |
|
551 |
Collections.sort(keys, comp); |
|
552 |
for (String key : keys) { |
|
553 |
out.println(" public static String "+key+";"); |
|
554 |
} |
|
555 |
|
|
556 |
// write end |
|
557 |
out.println("\n /**"); |
|
558 |
out.println(" * @param message the message containing parameters {0}...{N}"); |
|
559 |
out.println(" * @param bindings the parameters "); |
|
560 |
out.println(" * @return the given message's substitution locations with the given string values."); |
|
561 |
out.println(" */"); |
|
562 |
out.println(" public static String bind(String message, Object... bindings) {"); |
|
563 |
out.println(" return NLS.bind(message, bindings);"); |
|
564 |
out.println(" }"); |
|
565 |
|
|
566 |
out.println("\n static {"); |
|
567 |
out.println(" // initialize resource bundle"); |
|
568 |
out.println(" Utf8NLS.initializeMessages(BUNDLE_NAME, "+className+".class);"); |
|
569 |
out.println(" }"); |
|
570 |
|
|
571 |
out.println(" private "+className+"() { }"); |
|
572 |
out.println("}"); |
|
573 |
|
|
574 |
out.close(); |
|
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(); |
|
575 | 576 |
} |
576 | 577 |
|
577 | 578 |
public void summary() { |
... | ... | |
615 | 616 |
) { |
616 | 617 |
|
617 | 618 |
if (debug) { |
618 |
System.out.println("PluginMessages.createSourceFilesList(): adding source files " + file + "."); |
|
619 |
System.out.println("PluginMessagesManager.createSourceFilesList(): adding source files " + file + ".");
|
|
619 | 620 |
} |
620 | 621 |
else { |
621 | 622 |
//System.out.print("."); |
... | ... | |
632 | 633 |
public void createSourceFilesList() { |
633 | 634 |
|
634 | 635 |
if (debug) { |
635 |
System.out.println("PluginMessages.loadSourceFilesList(): creating source files list for extensions [" + StringUtils.join(this.srcFilesExtensions, ", ") + "]..."); |
|
636 |
System.out.println("PluginMessagesManager.loadSourceFilesList(): creating source files list for extensions [" + StringUtils.join(this.srcFilesExtensions, ", ") + "]...");
|
|
636 | 637 |
} |
637 | 638 |
|
638 | 639 |
this.createSourceFilesList(this.projectDirectory); |
639 | 640 |
|
640 | 641 |
|
641 | 642 |
if(debug) { |
642 |
System.out.println("PluginMessages.loadSourceFilesList(): done. Source files count = " + this.srcFiles.size() + "."); |
|
643 |
System.out.println("PluginMessagesManager.loadSourceFilesList(): done. Source files count = " + this.srcFiles.size() + ".");
|
|
643 | 644 |
} |
644 | 645 |
} |
645 | 646 |
|
... | ... | |
654 | 655 |
public void renameKey(String oldName, String newName) { |
655 | 656 |
|
656 | 657 |
if (!messageKeys.contains(oldName)) { |
657 |
System.err.println("PluginMessages.renameKey(): key=" + oldName + " not found, aborting renaming to " + newName + "."); |
|
658 |
System.err.println("PluginMessagesManager.renameKey(): key=" + oldName + " not found, aborting renaming to " + newName + ".");
|
|
658 | 659 |
return; |
659 | 660 |
} |
660 | 661 |
|
661 | 662 |
// continue only if key name has changed |
662 | 663 |
if(oldName.equals(newName)) { |
663 | 664 |
if(debug) { |
664 |
System.out.println("PluginMessages.renameKey(): no changes, skipped key: " + oldName + " = " + newName); |
|
665 |
System.out.println("PluginMessagesManager.renameKey(): no changes, skipped key: " + oldName + " = " + newName);
|
|
665 | 666 |
} |
666 | 667 |
return; |
667 | 668 |
} |
668 | 669 |
|
669 |
|
|
670 | 670 |
messageKeys.remove(oldName); |
671 | 671 |
messageKeys.add(newName); |
672 | 672 |
|
... | ... | |
688 | 688 |
*/ |
689 | 689 |
public void removeKey(String key) { |
690 | 690 |
if (!messageKeys.contains(key)) { |
691 |
System.err.println("PluginMessages.removeKey(): key=" + key + " not found, aborting removing."); |
|
691 |
System.err.println("PluginMessagesManager.removeKey(): key=" + key + " not found, aborting removing.");
|
|
692 | 692 |
return; |
693 | 693 |
} |
694 | 694 |
|
... | ... | |
735 | 735 |
*/ |
736 | 736 |
public void dump(BiHashMap<String, String> messages) { |
737 | 737 |
for (String key : messages.getKeys()) { |
738 |
System.out.println("PluginMessages.dump(): " + key + "=" + messages.get(key)); |
|
738 |
System.out.println("PluginMessagesManager.dump(): " + key + "=" + messages.get(key));
|
|
739 | 739 |
} |
740 | 740 |
} |
741 | 741 |
|
... | ... | |
744 | 744 |
* Dumps the keys replacements table. |
745 | 745 |
*/ |
746 | 746 |
public void dumpKeysReplacements() { |
747 |
System.out.println("PluginMessages.dumpKeysReplacements(): keys replacements table"); |
|
747 |
System.out.println("PluginMessagesManager.dumpKeysReplacements(): keys replacements table");
|
|
748 | 748 |
for (String key : this.keyModifications.keySet()) { |
749 |
System.out.println("PluginMessages.dumpKeysReplacements(): " + key + "=>" + this.keyModifications.get(key)); |
|
749 |
System.out.println("PluginMessagesManager.dumpKeysReplacements(): " + key + "=>" + this.keyModifications.get(key));
|
|
750 | 750 |
} |
751 | 751 |
} |
752 | 752 |
|
... | ... | |
794 | 794 |
//dict.summary(); |
795 | 795 |
|
796 | 796 |
|
797 |
//pmManager.saveChanges(true);
|
|
797 |
pmManager.saveChanges(true); |
|
798 | 798 |
|
799 |
System.out.println("PluginMessages.main(): done."); |
|
799 |
System.out.println("PluginMessagesManager.main(): done.");
|
|
800 | 800 |
} |
801 | 801 |
} |
Formats disponibles : Unified diff