Révision 1266
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java (revision 1266) | ||
---|---|---|
86 | 86 |
TreeSet<String> messageKeys = new TreeSet<String>(); |
87 | 87 |
|
88 | 88 |
/** |
89 |
* plugin.xml file -> contains eventually keys |
|
90 |
*/ |
|
91 |
protected File pluginXMLFile; |
|
92 |
|
|
93 |
public File getPluginXMLFile() { |
|
94 |
return pluginXMLFile; |
|
95 |
} |
|
96 |
|
|
97 |
public TreeSet<String> getOsgiKeys() { |
|
98 |
return osgiKeys; |
|
99 |
} |
|
100 |
|
|
101 |
public TreeMap<File, BiHashMap<String, String>> getOsgiLangs() { |
|
102 |
return osgiLangs; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* the OSGI-INF/l10n/bundle[_lang].properties OSGI message keys |
|
107 |
*/ |
|
108 |
TreeSet<String> osgiKeys = new TreeSet<String>(); |
|
109 |
|
|
110 |
/** |
|
111 |
* The OSGI messages stored by properties file |
|
112 |
*/ |
|
113 |
TreeMap<File, BiHashMap<String, String>> osgiLangs = new TreeMap<File, BiHashMap<String, String>>(); |
|
114 |
|
|
115 |
/** |
|
89 | 116 |
* Stores the key modifications for further saves in the source files |
90 | 117 |
*/ |
91 | 118 |
HashMap<String, String> keyModifications = new HashMap<String, String>(); |
... | ... | |
118 | 145 |
if (!messagesPackageDir.exists()) { |
119 | 146 |
messagesPackageDir = new File(projectDirectory2, "src/java/"+projectDirectory2.getName().replaceAll("\\.", "/")+"/messages"); |
120 | 147 |
} |
148 |
|
|
149 |
if (!messagesPackageDir.exists()) { |
|
150 |
messagesPackageDir = new File(projectDirectory2, "src/main/java/"+projectDirectory2.getName().replaceAll("\\.", "/")+"/messages"); |
|
151 |
} |
|
121 | 152 |
|
122 | 153 |
if (!messagesPackageDir.exists()) { |
123 | 154 |
return null; |
... | ... | |
155 | 186 |
|
156 | 187 |
this.javaMessageFile = javaMessageFile; |
157 | 188 |
this.projectDirectory = projectDirectory; |
189 |
this.pluginXMLFile = new File(projectDirectory, "plugin.xml"); |
|
158 | 190 |
this.srcFiles = new ArrayList<File>(); |
159 | 191 |
this.debug = debug; |
160 | 192 |
|
... | ... | |
201 | 233 |
|
202 | 234 |
//this.createKeysGlobalREGEX(); |
203 | 235 |
this.createUsedKeysFilesIndex(); |
236 |
|
|
237 |
// try loading OSGI messages |
|
238 |
if (pluginXMLFile.exists()) { |
|
239 |
ArrayList<String> result = IOUtils.findWithGroup(pluginXMLFile, "\"%([^\"]+)\""); |
|
240 |
osgiKeys.addAll(result); |
|
241 |
|
|
242 |
File osgiInf = new File(projectDirectory, "OSGI-INF/l10n"); |
|
243 |
if (osgiInf.exists()) { |
|
244 |
for (File propFile : osgiInf.listFiles()) { |
|
245 |
if (propFile.getName().startsWith("bundle") && propFile.getName().endsWith(".properties")) { |
|
246 |
Properties props = new Properties(); |
|
247 |
props.load(IOUtils.getReader(propFile)); |
|
248 |
osgiLangs.put(propFile, new BiHashMap<String, String>(props)); |
|
249 |
} |
|
250 |
} |
|
251 |
} |
|
252 |
System.out.println(osgiKeys); |
|
253 |
System.out.println(osgiLangs); |
|
254 |
} |
|
204 | 255 |
|
205 | 256 |
if(debug) { |
206 | 257 |
this.dumpUsedKeysFilesIndex(); |
... | ... | |
423 | 474 |
static { |
424 | 475 |
col.setStrength(Collator.TERTIARY); |
425 | 476 |
} |
426 |
public void saveChanges() throws IOException { |
|
477 |
public void saveChanges(boolean replaceFiles) throws IOException {
|
|
427 | 478 |
|
428 | 479 |
//Write prop File |
429 | 480 |
for (File propFile : langs.keySet()) { |
... | ... | |
432 | 483 |
@Override |
433 | 484 |
public synchronized Enumeration<Object> keys() { |
434 | 485 |
TreeSet<Object> set = new TreeSet<Object>(comp); |
486 |
System.out.println(set); |
|
435 | 487 |
set.addAll(super.keySet()); |
436 |
return Collections.enumeration(set); |
|
488 |
System.out.println(set); |
|
489 |
Enumeration<Object> en = Collections.enumeration(set); |
|
490 |
System.out.println(set); |
|
491 |
return en; |
|
437 | 492 |
} |
438 | 493 |
}; |
439 | 494 |
BiHashMap<String, String> h = langs.get(propFile); |
... | ... | |
442 | 497 |
} |
443 | 498 |
|
444 | 499 |
File newPropFile = new File(propFile.getParentFile(), propFile.getName()+".new"); |
500 |
if (replaceFiles) { |
|
501 |
propFile.delete(); |
|
502 |
newPropFile = propFile; |
|
503 |
} |
|
445 | 504 |
props.store(IOUtils.getWriter(newPropFile, ENCODING), "TXM messages generated by the PluginMessages class"); |
446 | 505 |
} |
447 | 506 |
|
... | ... | |
449 | 508 |
if (javaMessageFile == null) return; |
450 | 509 |
|
451 | 510 |
File newJavaMessageFile = new File(javaMessageFile.getParentFile(), javaMessageFile.getName()+".new"); |
511 |
if (replaceFiles) { |
|
512 |
javaMessageFile.delete(); |
|
513 |
newJavaMessageFile = javaMessageFile; |
|
514 |
} |
|
452 | 515 |
|
453 | 516 |
String className = getMessageClassName(); |
454 | 517 |
String name = getMessageName(); |
... | ... | |
469 | 532 |
out.println(" private static final String BUNDLE_NAME = \""+classPackage+".messages\"; //$NON-NLS-1$\n"); |
470 | 533 |
|
471 | 534 |
//write keys |
472 |
for (String key : this.getMessageKeys()) { |
|
535 |
ArrayList<String> keys = new ArrayList<String>(this.getMessageKeys()); |
|
536 |
Collections.sort(keys, comp); |
|
537 |
for (String key : keys) { |
|
473 | 538 |
out.println(" public static String "+key+";"); |
474 | 539 |
} |
475 | 540 |
|
... | ... | |
686 | 751 |
*/ |
687 | 752 |
public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException { |
688 | 753 |
|
689 |
File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
|
|
754 |
File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.rcp");
|
|
690 | 755 |
|
691 | 756 |
PluginMessages pmManager = new PluginMessages(projectFile); |
692 | 757 |
|
... | ... | |
714 | 779 |
//dict.summary(); |
715 | 780 |
|
716 | 781 |
|
717 |
pmManager.saveChanges();
|
|
782 |
//pmManager.saveChanges(true);
|
|
718 | 783 |
|
719 | 784 |
System.out.println("PluginMessages.main(): done."); |
720 | 785 |
} |
Formats disponibles : Unified diff