Revision 1560

tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ImportMessagesTable.java (revision 1560)
36 36
	}
37 37
	
38 38
	public boolean run(String prefix, File tableFile) throws Exception {
39
		if (!dir.exists()) return false;
39
		if (!dir.exists()) {
40
			System.out.println("dir nto found: "+dir);
41
			return false;
42
		}
40 43
		
41
		if (!tableFile.exists()) return false;
44
		if (!tableFile.exists()) {
45
			System.out.println("table file nto found: "+tableFile);
46
			return false;
47
		}
42 48
		
43 49
		File langPropertiesFile = new File(dir, prefix+"_"+lang+".properties");
44 50
		Properties slave = new Properties() {
......
116 122
	
117 123
	public static void main(String[] args) throws Exception {
118 124
		String prefix = "bundle"; // messages
119
		System.out.println(new ImportMessagesTable("fr").run(prefix, new File(prefix+".odt")));
125
		System.out.println(new ImportMessagesTable("fr").run(prefix, new File(prefix+"_fr-slh.odt")));
120 126
	}
121 127
}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessagesManager.java (revision 1560)
258 258
					for (File propFile : osgiInf.listFiles(IOUtils.FILTER_HIDDEN)) {
259 259
						if (propFile.getName().startsWith("bundle") && propFile.getName().endsWith(".properties")) {
260 260
							Properties props = new Properties();
261
							props.load(IOUtils.getReader(propFile));
261
							props.load(IOUtils.getReader(propFile, "ISO-8859-1"));
262 262
							HashMap<String, String> h = new HashMap<String, String>();
263 263
							for (Object k : props.keySet()) h.put(k.toString(), props.getProperty(k.toString()));
264 264
							osgiLangs.put(propFile, h);
......
549 549
			langs.get(p).put(key, message);
550 550
		}
551 551
	}
552
	
553 552

  
553

  
554 554
	public void putOSGI(String lang, String key, String message) {
555 555
		osgiKeys.add(key);
556 556

  
......
631 631

  
632 632
		if (javaMessageFile == null) return;
633 633

  
634
		//Write prop File
634
		// 1 Write bundle*.properties prop File
635
		for (File propFile : osgiLangs.keySet()) {
636

  
637
			Properties props = new Properties() {
638
				@Override
639
				public synchronized Enumeration<Object> keys() {
640
					TreeSet<Object> set = new TreeSet<Object>(comp);
641
					set.addAll(super.keySet());
642
					return Collections.enumeration(set);
643
				}
644
			};
645
			HashMap<String, String> h = osgiLangs.get(propFile);
646
			for (String k : h.keySet()) {
647
				props.setProperty(k, h.get(k));
648
			}
649

  
650
			File newPropFile = new File(propFile.getParentFile(), propFile.getName()+".new");
651
			if (replaceFiles) {
652
				propFile.delete();
653
				newPropFile = propFile;
654
			}
655
			props.store(IOUtils.getWriter(newPropFile, "ISO-8859-1"), "TXM OSGI messages generated by the PluginMessagesManager class");
656
		}
657

  
658
		// 2 Write messages*.properties prop File
635 659
		for (File propFile : langs.keySet()) {
636 660

  
637 661
			Properties props = new Properties() {
......
655 679
			props.store(IOUtils.getWriter(newPropFile, ENCODING), "TXM messages generated by the PluginMessagesManager class");
656 680
		}
657 681

  
658
		// write message File
682
		// 3 write Java message File
659 683
		File newJavaMessageFile = new File(javaMessageFile.getParentFile(), javaMessageFile.getName()+".new");
660 684

  
661 685
		ArrayList<String> lines = IOUtils.getLines(javaMessageFile, "UFT-8");
662 686
		TreeSet<String> oldKeys = new TreeSet<String>(IOUtils.findWithGroup(javaMessageFile, "public static String ([^\"=;]+);"));
663 687
		TreeSet<String> newKeys = new TreeSet<String>(messageKeys);
664 688
		TreeSet<String> writtenKeys = new TreeSet<String>();
665
		
689

  
666 690
		newKeys.removeAll(oldKeys);
667 691
		newKeys.removeAll(keyModifications.values()); // now contains only the very newly created keys
668 692

  

Also available in: Unified diff