35 |
35 |
* Also can not start by a number
|
36 |
36 |
*/
|
37 |
37 |
public static String javaKeyWords = "`^(abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|false|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|true|try|void|volatile|while)$`i";
|
38 |
|
|
|
38 |
|
39 |
39 |
/**
|
40 |
40 |
*
|
41 |
41 |
* @param debug show lot of debug messages
|
... | ... | |
58 |
58 |
System.out.println("NormalizeKeys.normalize(): ****************************************************************************************");
|
59 |
59 |
System.out.println("NormalizeKeys.normalize(): normalizating messages keys of project " + pmManager.getProjectDirectory() + "...");
|
60 |
60 |
}
|
61 |
|
|
|
61 |
|
62 |
62 |
HashMap<String, String> messages = pmManager.getMessagesForDefaultLang();
|
63 |
63 |
|
64 |
64 |
ArrayList<String> keys = new ArrayList<String>(pmManager.getMessageKeys());
|
65 |
65 |
ArrayList<String> normalized = new ArrayList<String>();
|
66 |
|
|
|
66 |
|
67 |
67 |
for (String key : keys) {
|
68 |
68 |
String value = messages.get(key);
|
69 |
69 |
if (value == null) {
|
... | ... | |
85 |
85 |
continue;
|
86 |
86 |
}
|
87 |
87 |
|
|
88 |
if (debug) System.out.print("K="+key+" ");
|
88 |
89 |
String newKeyOrig = normalize(messages.get(key));
|
89 |
90 |
if (newKeyOrig.length() == 0) {
|
90 |
91 |
//newKeyOrig = "EMPTY";
|
91 |
92 |
continue;
|
92 |
93 |
}
|
93 |
|
|
|
94 |
|
94 |
95 |
if (key.equals(newKeyOrig)) { // nothing to do
|
95 |
96 |
continue;
|
96 |
97 |
}
|
97 |
|
|
98 |
|
// if (value.equals(messages.get(newKeyOrig))) { // the newKey Value == the value
|
99 |
|
// //A=hello world
|
100 |
|
// //B=hello world
|
101 |
|
// // rename A -> helloWorld
|
102 |
|
// //B -> helloWorld SAUF QUE helloWorld existe ET meme valeur que valeur(B) valeur(helloWorld)
|
103 |
|
//
|
104 |
|
// pmManager.removeKey(key); // remove the old key
|
105 |
|
// } else {
|
106 |
|
// A=hello world
|
107 |
|
// B=hello world!
|
108 |
|
// A et B n'ont pas la meme clé
|
109 |
|
|
110 |
|
String newKey = ""+newKeyOrig;
|
111 |
|
int c = 2;
|
112 |
|
while (pmManager.getMessageKeys().contains(newKey)) {
|
113 |
|
newKey = newKeyOrig+"_"+(c++);
|
114 |
|
}
|
115 |
98 |
|
116 |
|
pmManager.renameKey(key, newKey);
|
117 |
|
normalized.add(key + " => " + newKey);
|
118 |
|
// }
|
|
99 |
// if (value.equals(messages.get(newKeyOrig))) { // the newKey Value == the value
|
|
100 |
// //A=hello world
|
|
101 |
// //B=hello world
|
|
102 |
// // rename A -> helloWorld
|
|
103 |
// //B -> helloWorld SAUF QUE helloWorld existe ET meme valeur que valeur(B) valeur(helloWorld)
|
|
104 |
//
|
|
105 |
// pmManager.removeKey(key); // remove the old key
|
|
106 |
// } else {
|
|
107 |
// A=hello world
|
|
108 |
// B=hello world!
|
|
109 |
// A et B n'ont pas la meme clé
|
|
110 |
|
|
111 |
String newKey = ""+newKeyOrig;
|
|
112 |
int c = 2;
|
|
113 |
while (pmManager.getMessageKeys().contains(newKey)) {
|
|
114 |
newKey = newKeyOrig+"_"+(c++);
|
|
115 |
}
|
|
116 |
|
|
117 |
pmManager.renameKey(key, newKey);
|
|
118 |
normalized.add(key + " => " + newKey);
|
|
119 |
// }
|
119 |
120 |
}
|
120 |
121 |
|
121 |
122 |
if(debug) {
|
... | ... | |
125 |
126 |
}
|
126 |
127 |
|
127 |
128 |
// Log
|
128 |
|
System.out.println(" Done: " + normalized.size() + " changes: ");
|
129 |
|
for (int i = 0; i < normalized.size(); i++) {
|
130 |
|
System.out.println(" " + normalized.get(i));
|
|
129 |
if (normalized.size() > 0) {
|
|
130 |
System.out.println(" Done: "+pmManager.getMessageName() + " " + normalized.size() + " changes: ");
|
|
131 |
for (int i = 0; i < normalized.size(); i++) {
|
|
132 |
System.out.println(" " + normalized.get(i));
|
|
133 |
}
|
131 |
134 |
}
|
132 |
|
|
133 |
135 |
return normalized.size();
|
134 |
136 |
}
|
135 |
137 |
|
... | ... | |
138 |
140 |
* @param str
|
139 |
141 |
*/
|
140 |
142 |
public static String normalize(String str) {
|
141 |
|
|
|
143 |
|
142 |
144 |
// log
|
143 |
145 |
if(debug) {
|
144 |
146 |
System.out.println("NormalizeKeys.normalize(): normalizing: " + str);
|
... | ... | |
148 |
150 |
|
149 |
151 |
// replace the parameters binding
|
150 |
152 |
str = str.replaceAll("(\\{[0-9]})", "P$1");
|
151 |
|
|
|
153 |
|
152 |
154 |
// special replacements
|
153 |
155 |
str = str.replaceAll("%", "Percent");
|
154 |
156 |
str = str.replaceAll("=", "Equals");
|
155 |
157 |
str = str.replaceAll("@", "At");
|
156 |
|
|
|
158 |
|
157 |
159 |
// remove all special chars
|
158 |
160 |
str = str.replaceAll("[^a-zA-Z0-9 ]", "").trim();
|
159 |
161 |
|
... | ... | |
200 |
202 |
if(str.matches(javaKeyWords) || str.matches("^[0-9].*$")) {
|
201 |
203 |
str = "_" + str;
|
202 |
204 |
}
|
203 |
|
|
|
205 |
|
204 |
206 |
// log
|
205 |
207 |
if(debug) {
|
206 |
208 |
System.out.println(" => " + str);
|
... | ... | |
252 |
254 |
// e.printStackTrace();
|
253 |
255 |
// }
|
254 |
256 |
|
255 |
|
NormalizeKeys keysNormalizer = new NormalizeKeys(false);
|
|
257 |
NormalizeKeys keysNormalizer = new NormalizeKeys(true);
|
256 |
258 |
|
257 |
259 |
WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false);
|
258 |
260 |
int total = 0;
|
259 |
261 |
for (PluginMessagesManager pm : wmm.getPluginMessages().values()) {
|
|
262 |
|
|
263 |
//if (!pm.getProjectDirectory().getName().equals("org.txm.ca.rcp")) continue;
|
|
264 |
|
260 |
265 |
total += keysNormalizer.normalize(pm);
|
261 |
|
|
|
266 |
|
262 |
267 |
pm.saveChanges(true); // mode homme
|
263 |
268 |
//pm.saveChanges(false);
|
|
269 |
|
|
270 |
if (pm.getProjectDirectory().getName().equals("org.txm.ca.rcp")) {
|
|
271 |
System.out.println("KEYS2="+pm.getMessageKeys());
|
|
272 |
}
|
264 |
273 |
}
|
265 |
|
|
|
274 |
|
266 |
275 |
if (total > 0) {
|
267 |
276 |
wmm.saveKeyModificationsInSources();
|
268 |
277 |
System.out.println("Done: "+total+" changes.");
|
... | ... | |
270 |
279 |
System.out.println("Done: no change.");
|
271 |
280 |
}
|
272 |
281 |
|
273 |
|
// WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false);
|
274 |
|
//
|
275 |
|
// for (PluginMessagesManager pmManager : wmm.getPluginMessages().values()) {
|
276 |
|
// File projectFile = pmManager.getProjectDirectory();
|
277 |
|
// if (!projectFile.getName().equals("org.txm.ahc.core")) continue;
|
278 |
|
//
|
279 |
|
// keysNormalizer.normalize(pmManager);
|
280 |
|
//
|
281 |
|
// pmManager.saveChanges(true); // mode homme
|
282 |
|
// //pmManager.saveChanges(false);
|
283 |
|
// }
|
284 |
|
//
|
285 |
|
// wmm.saveKeyModificationsInSources();
|
286 |
|
|
|
282 |
// WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false);
|
|
283 |
//
|
|
284 |
// for (PluginMessagesManager pmManager : wmm.getPluginMessages().values()) {
|
|
285 |
// File projectFile = pmManager.getProjectDirectory();
|
|
286 |
// if (!projectFile.getName().equals("org.txm.ahc.core")) continue;
|
|
287 |
//
|
|
288 |
// keysNormalizer.normalize(pmManager);
|
|
289 |
//
|
|
290 |
// pmManager.saveChanges(true); // mode homme
|
|
291 |
// //pmManager.saveChanges(false);
|
|
292 |
// }
|
|
293 |
//
|
|
294 |
// wmm.saveKeyModificationsInSources();
|
287 |
295 |
|
288 |
|
// WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false);
|
289 |
|
//
|
290 |
|
// for (PluginMessagesManager pmManager : wmm.getPluginMessages().values()) {
|
291 |
|
// //System.out.println(pmManager.getProjectDirectory().getName());
|
292 |
|
// if (pmManager.getProjectDirectory().getName().equals("org.txm.chartsengine.jfreechart.core")) {
|
293 |
|
// System.out.println("INDEX jfc core="+pmManager.getUsedKeysFilesIndex());
|
294 |
|
// }
|
295 |
|
// if (!pmManager.getProjectDirectory().getName().equals("org.txm.chartsengine.core")) continue;
|
296 |
|
//
|
297 |
|
//
|
298 |
|
//// System.out.println("KEYS="+pmManager.getMessageKeys());
|
299 |
|
// keysNormalizer.normalize(pmManager);
|
300 |
|
//// System.out.println("KEYS2="+pmManager.getMessageKeys());
|
301 |
|
//// System.out.println("MODIFS="+pmManager.getKeyModifications());
|
302 |
|
// //pmManager.saveChanges(true); // mode homme
|
303 |
|
//
|
304 |
|
// //pmManager.saveChanges(false);
|
305 |
|
//
|
306 |
|
// System.out.println("INDEX="+pmManager.getUsedKeysFilesIndex());
|
307 |
|
// }
|
308 |
|
//
|
309 |
|
// //System.out.println("FULLINDEX="+wmm.getUsedKeysFilesIndex().);
|
310 |
|
// //wmm.saveKeyModificationsInSources();
|
|
296 |
|
|
297 |
// WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false);
|
|
298 |
//
|
|
299 |
// for (PluginMessagesManager pmManager : wmm.getPluginMessages().values()) {
|
|
300 |
// //System.out.println(pmManager.getProjectDirectory().getName());
|
|
301 |
// if (pmManager.getProjectDirectory().getName().equals("org.txm.chartsengine.jfreechart.core")) {
|
|
302 |
// System.out.println("INDEX jfc core="+pmManager.getUsedKeysFilesIndex());
|
|
303 |
// }
|
|
304 |
// if (!pmManager.getProjectDirectory().getName().equals("org.txm.chartsengine.core")) continue;
|
|
305 |
//
|
|
306 |
//
|
|
307 |
//// System.out.println("KEYS="+pmManager.getMessageKeys());
|
|
308 |
// keysNormalizer.normalize(pmManager);
|
|
309 |
//// System.out.println("KEYS2="+pmManager.getMessageKeys());
|
|
310 |
//// System.out.println("MODIFS="+pmManager.getKeyModifications());
|
|
311 |
// //pmManager.saveChanges(true); // mode homme
|
|
312 |
//
|
|
313 |
// //pmManager.saveChanges(false);
|
|
314 |
//
|
|
315 |
// System.out.println("INDEX="+pmManager.getUsedKeysFilesIndex());
|
|
316 |
// }
|
|
317 |
//
|
|
318 |
// //System.out.println("FULLINDEX="+wmm.getUsedKeysFilesIndex().);
|
|
319 |
// //wmm.saveKeyModificationsInSources();
|
311 |
320 |
}
|
312 |
321 |
}
|