Révision 1239

tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1239)
1 1
package org.txm.rcp.translate.devtools;
2 2

  
3
import org.eclipse.osgi.util.NLS;
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.IOException;
6
import java.io.UnsupportedEncodingException;
7

  
8
import org.txm.rcp.translate.i18n.PluginMessages;
4 9
import org.txm.utils.BiHashMap;
5 10

  
6 11
/**
......
105 110
	 */
106 111
	public static void main(String[] args) {
107 112

  
108
		System.out.println("NormalizeKeys.main(): starting process...");
109
		
110
		// tests
111
		System.out.println(NLS.bind("lol {0}", 1));
112
		
113
		BiHashMap<String, String> messages = new BiHashMap<String, String>();
114
		messages.put("Convert5To6_46", "Error while computing."); 
115
		messages.put("Convert5To6_46", "** Error: the connexion to the server failed: wrong port format");
116
		messages.put("Convert5To6_6", "** Error: ''{0}'' corpus directory is not conformant to TXM corpus binary format: corpus skipped.");
117
		messages.put("common_lowestFrequency", "Lowest frequency");
118
		messages.put("Convert5To6_27", "T");
119
		messages.put("Convert5To6_28", "");
120
		messages = normalize(messages);
113
		try {
114
			System.out.println("NormalizeKeys.main(): starting process...");
115
			
116
			File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
117
			File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
118
			
119
			PluginMessages pmManager = new PluginMessages(projectFile, messageFile);
121 120

  
122
		System.out.println("NormalizeKeys.main(): terminated.");
123
		
121
			
122
			// tests
123
			BiHashMap<String, String> messages = new BiHashMap<String, String>();
124
			messages.put("Convert5To6_46", "Error while computing."); 
125
			messages.put("Convert5To6_46", "** Error: the connexion to the server failed: wrong port format");
126
			messages.put("Convert5To6_6", "** Error: ''{0}'' corpus directory is not conformant to TXM corpus binary format: corpus skipped.");
127
			messages.put("common_lowestFrequency", "Lowest frequency");
128
			messages.put("Convert5To6_27", "T");
129
			messages.put("Convert5To6_28", "");
130
			messages = normalize(messages);
131

  
132
			pmManager.dump(messages);
133
			
134
			System.out.println("NormalizeKeys.main(): terminated.");
135
			
124 136
//		HashSet<String> strings = new HashSet<String>();
125 137
//		strings.add("Error while computing.");
126 138
//		strings.add("** Error: the connexion to the server failed: wrong port format");
......
128 140
//		strings.add("T");
129 141
//		strings.add("");
130 142
//		normalize(strings);
143
		}
144
		catch (UnsupportedEncodingException e) {
145
			// TODO Auto-generated catch block
146
			e.printStackTrace();
147
		}
148
		catch (FileNotFoundException e) {
149
			// TODO Auto-generated catch block
150
			e.printStackTrace();
151
		}
152
		catch (IOException e) {
153
			// TODO Auto-generated catch block
154
			e.printStackTrace();
155
		}
131 156
		
132 157
	}
133 158
	
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java (revision 1239)
344 344

  
345 345
	
346 346
	/**
347
	 * Returns the keys of all messages that are not used in the project.
347
	 * Returns the keys of all messages that are not used in the project itself.
348 348
	 * @return
349 349
	 */
350 350
	public ArrayList<String> findUnusedKeys()	{
......
372 372
	 * @throws IOException
373 373
	 */
374 374
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
375
		
375 376
		File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
376 377
		File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
377
		PluginMessages dict = new PluginMessages(projectFile, messageFile);
378 378
		
379
		PluginMessages pmManager = new PluginMessages(projectFile, messageFile);
380
		
379 381
		// test to find files using the specified key
380
		HashMap<File, String> files = dict.getFilesUsingKey("Base_5");
382
		HashMap<File, String> files = pmManager.getFilesUsingKey("Base_5");
381 383
		for (Map.Entry<File, String> entry : files.entrySet()) {
382 384
		    System.out.println("find files using key: file " + entry.getKey() + " contains key " + entry.getValue());
383 385
		}
384 386
		
385 387
		// test to find unused keys
386
		ArrayList<String> unusedKeys = dict.findUnusedKeys();
388
		ArrayList<String> unusedKeys = pmManager.findUnusedKeys();
387 389
		for (int i = 0; i < unusedKeys.size(); i++) {
388
			System.out.println("findUnusedKeys: key " + unusedKeys.get(i) + " is unused in project " + dict.getProjectDirectory() + " (main language value = " + dict.getMessagesForLang("").get(unusedKeys.get(i)) + ")");	
390
			System.out.println("findUnusedKeys: key " + unusedKeys.get(i) + " is unused in project " + pmManager.getProjectDirectory() + " (main language value = " + pmManager.getMessagesForLang("").get(unusedKeys.get(i)) + ")");	
389 391
		}
390 392
		
391 393
		//dict.summary();
......
409 411
	public File getProjectDirectory() {
410 412
		return projectDirectory;
411 413
	}
414
	
415
	
416
	/**
417
     * Dumps the specified BiHashMap<String, String> to standard output.
418
     */
419
    public void dump(BiHashMap<String, String> messages)	{
420
    	for (String key : messages.getKeys()) {
421
			System.out.println("PluginMessages.dump(): " + key + "=" + messages.get(key));
422
		}
423
    }
412 424
}

Formats disponibles : Unified diff