Révision 1233
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1233) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.translate.devtools; |
2 | 2 |
|
3 |
import java.util.HashSet; |
|
4 |
|
|
5 | 3 |
import org.eclipse.osgi.util.NLS; |
6 | 4 |
import org.txm.utils.BiHashMap; |
7 | 5 |
|
8 | 6 |
/** |
9 |
* Normalizes the keys using the message words.
|
|
7 |
* Normalizes the keys using the words of the message sentence.
|
|
10 | 8 |
* eg. : "Error while computing." => errorWhileComputing |
11 | 9 |
* |
12 | 10 |
* |
... | ... | |
24 | 22 |
public static String preserve = "^(common_|error_|info_).*$"; |
25 | 23 |
|
26 | 24 |
/** |
27 |
* |
|
25 |
* Normalizes the keys of the specified messages map.
|
|
28 | 26 |
* @param messages |
29 | 27 |
* @return |
30 | 28 |
*/ |
... | ... | |
45 | 43 |
} |
46 | 44 |
|
47 | 45 |
messages.put(normalize(messages.get(key)), messages.get(key)); |
46 |
//messages.removeByKey(key); |
|
48 | 47 |
} |
49 | 48 |
|
50 | 49 |
return messages; |
51 | 50 |
} |
52 | 51 |
|
53 |
// /** |
|
54 |
// * |
|
55 |
// * @param strings |
|
56 |
// * @return |
|
57 |
// */ |
|
58 |
// public static HashSet<String> normalize(HashSet<String> strings) { |
|
59 |
// for (String str : strings) { |
|
60 |
// if(debug) { |
|
61 |
// System.out.println(str); |
|
62 |
// System.out.println(" => " + normalize(str)); |
|
63 |
// } |
|
64 |
// } |
|
65 |
// |
|
66 |
// return strings; |
|
67 |
// } |
|
68 |
|
|
69 |
|
|
52 |
|
|
70 | 53 |
/** |
71 |
* |
|
54 |
* Normalizes the specified string.
|
|
72 | 55 |
* @param str |
73 | 56 |
*/ |
74 | 57 |
public static String normalize(String str) { |
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/FindUnusedKeys.java (revision 1233) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.translate.devtools; |
2 | 2 |
|
3 |
/** |
|
4 |
* Checks that all key defined in Messages.java are used in the source files. |
|
5 |
* |
|
6 |
* @author sjacquot |
|
7 |
* |
|
8 |
*/ |
|
3 | 9 |
public class FindUnusedKeys { |
4 | 10 |
|
5 | 11 |
} |
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/WorkspaceMessagesManager.java (revision 1233) | ||
---|---|---|
7 | 7 |
import java.util.LinkedHashMap; |
8 | 8 |
|
9 | 9 |
/** |
10 |
* Manages the messages of the TXM projects of a RCP workspace |
|
10 |
* Manages the messages of the TXM projects of an RCP workspace
|
|
11 | 11 |
* |
12 | 12 |
* @author mdecorde |
13 | 13 |
* |
... | ... | |
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
public WorkspaceMessagesManager(File workspaceLocation) throws UnsupportedEncodingException, FileNotFoundException, IOException { |
32 |
|
|
32 | 33 |
this.workspaceLocation = workspaceLocation; |
33 | 34 |
|
35 |
//System.out.println("WorkspaceMessagesManager.WorkspaceMessagesManager(): workspace location = " + this.workspaceLocation); |
|
36 |
|
|
34 | 37 |
if (!workspaceLocation.exists()) return; |
35 | 38 |
if (!workspaceLocation.isDirectory()) return; |
36 | 39 |
|
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java (revision 1233) | ||
---|---|---|
8 | 8 |
import java.io.InputStreamReader; |
9 | 9 |
import java.io.PrintWriter; |
10 | 10 |
import java.io.UnsupportedEncodingException; |
11 |
import java.nio.file.Files; |
|
12 |
import java.nio.file.Paths; |
|
13 |
import java.util.ArrayList; |
|
11 | 14 |
import java.util.HashMap; |
12 |
import java.util.Hashtable; |
|
13 | 15 |
import java.util.LinkedHashSet; |
14 | 16 |
import java.util.Properties; |
15 | 17 |
|
... | ... | |
34 | 36 |
BiHashMap<File, String> file2lang = new BiHashMap<File, String>(); |
35 | 37 |
|
36 | 38 |
public PluginMessages(File projectDirectory, File messageFile) throws UnsupportedEncodingException, FileNotFoundException, IOException { |
39 |
|
|
37 | 40 |
this.messageFile = messageFile; |
38 | 41 |
this.projectDirectory = projectDirectory; |
42 |
|
|
43 |
System.out.println("********************************************************************************************************************"); |
|
44 |
System.out.println("PluginMessages.PluginMessages(): project directory = " + this.projectDirectory); |
|
45 |
System.out.println("PluginMessages.PluginMessages(): message file = " + this.messageFile); |
|
46 |
|
|
39 | 47 |
File[] propFiles = messageFile.getParentFile().listFiles(); |
40 | 48 |
for (File propFile : propFiles) { |
41 | 49 |
String name = propFile.getName(); |
... | ... | |
206 | 214 |
} |
207 | 215 |
|
208 | 216 |
public void summary() { |
217 |
|
|
209 | 218 |
System.out.println(getMessageClassName()); |
219 |
|
|
210 | 220 |
System.out.println("Messages keys"); |
211 | 221 |
for (String key : messageKeys) { |
212 |
System.out.println(" $key");
|
|
222 |
System.out.println(key);
|
|
213 | 223 |
} |
214 | 224 |
|
215 | 225 |
System.out.println("Langs"); |
216 | 226 |
for (File lang : langs.keySet()) { |
217 |
System.out.println(" '$lang'"); |
|
227 |
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------"); |
|
228 |
System.out.println(" " + lang); |
|
229 |
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------"); |
|
218 | 230 |
BiHashMap<String, String> hash = langs.get(lang); |
219 | 231 |
System.out.println(" keys="+ hash.getKeys()); |
220 | 232 |
for (String key : hash.getKeys()) { |
221 |
System.out.println(" $key="+hash.get(key));
|
|
233 |
System.out.println(" " + key + "="+hash.get(key));
|
|
222 | 234 |
} |
223 | 235 |
} |
224 | 236 |
} |
225 | 237 |
|
238 |
|
|
239 |
public void walk(File path, String fileExtension) { |
|
240 |
|
|
241 |
File[] list = path.listFiles(); |
|
242 |
|
|
243 |
if (list == null) { |
|
244 |
return; |
|
245 |
} |
|
246 |
|
|
247 |
for (File f : list) { |
|
248 |
if (f.isDirectory()) { |
|
249 |
this.walk(f, fileExtension); |
|
250 |
// System.out.println( "Dir:" + f.getAbsoluteFile() ); |
|
251 |
} |
|
252 |
else if (f.getName().endsWith(fileExtension) |
|
253 |
//&& !f.equals(this.messageFile) |
|
254 |
) { |
|
255 |
|
|
256 |
System.out.println("File: " + f.getAbsoluteFile()); |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
|
|
261 |
/** |
|
262 |
* Returns all Java files using the specified message key. |
|
263 |
* @param key |
|
264 |
*/ |
|
265 |
public void getFilesUsingKey(String key) { |
|
266 |
this.walk(this.projectDirectory, ".java"); |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* |
|
271 |
* @param args |
|
272 |
* @throws UnsupportedEncodingException |
|
273 |
* @throws FileNotFoundException |
|
274 |
* @throws IOException |
|
275 |
*/ |
|
226 | 276 |
public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException { |
227 |
File projectFile = new File("/home/mdecorde/workspace047/org.txm.core");
|
|
277 |
File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
|
|
228 | 278 |
File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java"); |
229 | 279 |
PluginMessages dict = new PluginMessages(projectFile, messageFile); |
230 | 280 |
|
281 |
|
|
282 |
//dict.getFilesUsingKey("test"); |
|
283 |
|
|
231 | 284 |
dict.summary(); |
232 | 285 |
//dict.saveChanges(); |
233 | 286 |
} |
... | ... | |
239 | 292 |
public HashMap<File, BiHashMap<String, String>> getLangs() { |
240 | 293 |
return langs; |
241 | 294 |
} |
295 |
|
|
296 |
/** |
|
297 |
* Gets the project root directory. |
|
298 |
* @return the projectDirectory |
|
299 |
*/ |
|
300 |
public File getProjectDirectory() { |
|
301 |
return projectDirectory; |
|
302 |
} |
|
242 | 303 |
} |
Formats disponibles : Unified diff