Révision 1315
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1315) | ||
---|---|---|
34 | 34 |
* Java keywords that can not be used as variable name. |
35 | 35 |
* Also can not start by a number |
36 | 36 |
*/ |
37 |
public static String illegalJavaStartingStr = "^([0-9]|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)$";
|
|
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 |
* |
... | ... | |
64 | 64 |
ArrayList<String> keys = new ArrayList<String>(pmManager.getMessageKeys()); |
65 | 65 |
ArrayList<String> normalized = new ArrayList<String>(); |
66 | 66 |
|
67 |
int n = 0; |
|
68 | 67 |
for (String key : keys) { |
69 | 68 |
String value = messages.get(key); |
70 | 69 |
if (value == null) { |
... | ... | |
115 | 114 |
} |
116 | 115 |
|
117 | 116 |
pmManager.renameKey(key, newKey); |
118 |
normalized.add(key); |
|
117 |
normalized.add(key + " => " + newKey);
|
|
119 | 118 |
// } |
120 |
n++; |
|
121 | 119 |
} |
122 | 120 |
|
123 | 121 |
if(debug) { |
... | ... | |
126 | 124 |
System.out.println("NormalizeKeys.normalize(): number of replacements to do: " + pmManager.getKeyModifications().size() + "."); |
127 | 125 |
} |
128 | 126 |
|
129 |
if (n > 0) { |
|
130 |
System.out.println(" Done: "+n+" changes: "+normalized); |
|
127 |
// 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)); |
|
131 | 131 |
} |
132 | 132 |
|
133 |
return n; |
|
133 |
return normalized.size();
|
|
134 | 134 |
} |
135 | 135 |
|
136 | 136 |
/** |
... | ... | |
151 | 151 |
|
152 | 152 |
// special replacements |
153 | 153 |
str = str.replaceAll("%", "percent"); |
154 |
str = str.replaceAll("=", "equals"); |
|
154 | 155 |
|
155 | 156 |
// remove all special chars |
156 | 157 |
str = str.replaceAll("[^a-zA-Z0-9 ]", "").trim(); |
... | ... | |
194 | 195 |
str = tmpString; |
195 | 196 |
} |
196 | 197 |
|
197 |
// java variable can not start by a number and
|
|
198 |
if(str.matches(illegalJavaStartingStr) || str.matches("[0-9]+")) {
|
|
198 |
// java variable can not start by a number or be a java keyword
|
|
199 |
if(str.matches(javaKeyWords) || str.matches("^[0-9].*?$")) {
|
|
199 | 200 |
str = "_" + str; |
200 | 201 |
} |
201 |
|
|
202 |
|
|
202 | 203 |
// log |
203 | 204 |
if(debug) { |
204 | 205 |
System.out.println(" => " + str); |
... | ... | |
250 | 251 |
// e.printStackTrace(); |
251 | 252 |
// } |
252 | 253 |
|
253 |
NormalizeKeys keysNormalizer = new NormalizeKeys(false);
|
|
254 |
NormalizeKeys keysNormalizer = new NormalizeKeys(true);
|
|
254 | 255 |
|
255 | 256 |
// WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false); |
256 | 257 |
// int total = 0; |
... | ... | |
282 | 283 |
// |
283 | 284 |
// wmm.saveKeyModificationsInSources(); |
284 | 285 |
|
285 |
WorkspaceMessagesManager wmm = new WorkspaceMessagesManager(false); |
|
286 |
|
|
287 |
for (PluginMessagesManager pmManager : wmm.getPluginMessages().values()) { |
|
288 |
File projectFile = pmManager.getProjectDirectory(); |
|
289 |
if (!projectFile.getName().equals("org.txm.progression.rcp")) continue; |
|
286 |
//File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core"); |
|
287 |
File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.progression.core"); |
|
288 |
PluginMessagesManager pmManager = new PluginMessagesManager(projectFile, true); |
|
289 |
keysNormalizer.normalize(pmManager); |
|
290 | 290 |
|
291 |
keysNormalizer.normalize(pmManager); |
|
292 |
|
|
293 |
pmManager.saveChanges(true); // mode homme |
|
291 |
//pmManager.saveChanges(true); // mode homme |
|
294 | 292 |
//pmManager.saveChanges(false); |
295 | 293 |
} |
296 | 294 |
|
297 |
wmm.saveKeyModificationsInSources(); |
|
298 |
} |
|
299 | 295 |
} |
Formats disponibles : Unified diff