Révision 1256

tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1256)
60 60
				System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); 
61 61
				continue;
62 62
			}
63
			String oldKey = key;
64 63
			String newKey = normalize(messages.get(key));
65
			pmManager.renameKey(oldKey, newKey);
64
			pmManager.renameKey(key, newKey);
66 65
			
67 66
			//messages.put(normalize(messages.get(key)), messages.get(key));
68 67
			
......
76 75
	
77 76
	
78 77
	
79
	/**
80
	 * Normalizes the keys of the specified messages map.
81
	 * @param messages
82
	 * @return
83
	 */
84
	public BiHashMap<String, String> normalize(BiHashMap<String, String> messages)	{
85
		
86
		for (String key : messages.getKeys()) {
87
			String value = messages.get(key);
88
			
89
			// already formatted message
90
			if(key.matches(preserve))	{
91
				System.err.println("NormalizeKeys.normalize(): warning: skipped: " + key + "=" + value);
92
				continue;
93
			}
94
			// empty message
95
			else if(value.length() == 0)	{
96
				System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); 
97
				continue;
98
			}
99
			
100
			messages.put(normalize(messages.get(key)), messages.get(key));
101
			//messages.removeByKey(key);
102
		}
103
		
104
		return messages;
105
	}
106
	
78
//	/**
79
//	 * Normalizes the keys of the specified messages map.
80
//	 * @param messages
81
//	 * @return
82
//	 */
83
//	public BiHashMap<String, String> normalize(BiHashMap<String, String> messages)	{
84
//		
85
//		for (String key : messages.getKeys()) {
86
//			String value = messages.get(key);
87
//			
88
//			// already formatted message
89
//			if(key.matches(preserve))	{
90
//				System.err.println("NormalizeKeys.normalize(): warning: skipped: " + key + "=" + value);
91
//				continue;
92
//			}
93
//			// empty message
94
//			else if(value.length() == 0)	{
95
//				System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); 
96
//				continue;
97
//			}
98
//			
99
//			messages.put(normalize(messages.get(key)), messages.get(key));
100
//			//messages.removeByKey(key);
101
//		}
102
//		
103
//		return messages;
104
//	}
105
//	
107 106

  
108 107
	/**
109 108
	 * Normalizes the specified string.
......
176 175
			File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
177 176
			File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
178 177
			
179
			PluginMessages pmManager = new PluginMessages(projectFile, messageFile);
178
			PluginMessages pmManager = new PluginMessages(projectFile, messageFile, false);
180 179
			NormalizeKeys keysNormalizer = new NormalizeKeys(true);
181 180
			
182 181
			// tests
......
185 184
			//pmManager.dump(pmManager.getMessagesForLang(""));
186 185
			pmManager.dumpKeysReplacements();
187 186
			
188
			
187
			System.out.println("NormalizeKeys.main(): number of replacements to do: " + pmManager.getKeyModifications().size() + ".");
188

  
189 189
			System.out.println("NormalizeKeys.main(): terminated.");
190 190
			
191 191
//		HashSet<String> strings = new HashSet<String>();
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/WorkspaceMessagesManager.java (revision 1256)
10 10
import java.util.Map;
11 11
import java.util.TreeSet;
12 12

  
13
import org.txm.rcp.translate.devtools.NormalizeKeys;
13 14
import org.txm.utils.io.IOUtils;
14 15

  
15 16
/**
......
95 96
		System.out.println("WorkspaceMessagesManager.WorkspaceMessagesManager(): numbers of used keys: " + this.usedKeysFilesIndex.size() + ".");
96 97
		System.out.println("WorkspaceMessagesManager.WorkspaceMessagesManager(): numbers of unused keys: " + PluginMessages.getUnusedKeys(this.usedKeysFilesIndex, false).size() + ".");
97 98
		System.out.println("WorkspaceMessagesManager.WorkspaceMessagesManager(): done.");
99
		
100
		
101
		
102
		
103
		// FIXME normalizer test
104
//		File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
105
//		File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
106
//		
107
//		PluginMessages pmManager = new PluginMessages(projectFile, messageFile);
108
//		NormalizeKeys keysNormalizer = new NormalizeKeys(true);
109
//		
110
//		// tests
111
//		keysNormalizer.normalize(pmManager);
112
//
113
//		//pmManager.dump(pmManager.getMessagesForLang(""));
114
//		pmManager.dumpKeysReplacements();
115
		
116
		
117
		
98 118
	}
99 119

  
100 120
	/**
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java (revision 1256)
39 39
	/**
40 40
	 * Debug state.
41 41
	 */
42
	public boolean debug = true;
42
	protected boolean debug;
43 43

  
44 44
	/**
45 45
	 * Project root directory.
......
92 92
	 */
93 93
	BiHashMap<File, String> file2lang = new BiHashMap<File, String>();
94 94
	
95
	
96
	
97
	
95 98
	/**
96 99
	 * 
97 100
	 * @param projectDirectory
......
101 104
	 * @throws IOException
102 105
	 */
103 106
	public PluginMessages(File projectDirectory, File javaMessageFile) throws UnsupportedEncodingException, FileNotFoundException, IOException {
107
		this(projectDirectory, javaMessageFile, true);
108
	}
109
	
110
	/**
111
	 * 
112
	 * @param projectDirectory
113
	 * @param javaMessageFile
114
	 * @throws UnsupportedEncodingException
115
	 * @throws FileNotFoundException
116
	 * @throws IOException
117
	 */
118
	public PluginMessages(File projectDirectory, File javaMessageFile, boolean debug) throws UnsupportedEncodingException, FileNotFoundException, IOException {
104 119

  
105 120
		this.javaMessageFile = javaMessageFile;
106 121
		this.projectDirectory = projectDirectory;
107 122
		this.srcFiles = new ArrayList<File>();
108

  
123
		this.debug = debug;
124
		
109 125
		System.out.println("********************************************************************************************************************");
110 126
		System.out.println("PluginMessages.PluginMessages(): project root directory = " + this.projectDirectory);
111 127
		System.out.println("PluginMessages.PluginMessages(): java message file = " + this.javaMessageFile);
......
188 204
			if(debug) {
189 205
				System.out.println("PluginMessages.createUsedKeysIndex(): looking for key " + this.getKeyFullName(key) + " in project source files...");
190 206
			}
207
			else	{
208
				System.out.print(".");
209
			}
191 210

  
211

  
192 212
			for (File file : this.srcFiles) {
193 213
					ArrayList<String> lines = IOUtils.getLines(file, PluginMessages.ENCODING);
194 214
					
......
439 459
				if(debug) {
440 460
					System.out.println("PluginMessages.createSourceFilesList(): adding source files " + file + ".");
441 461
				}
462
				else	{
463
					System.out.print(".");
464
				}
442 465

  
443 466
				this.srcFiles.add(file);
444 467
			}
......
475 498
			return;
476 499
		}
477 500
		
501
		// continue only if key name has changed
502
		if(oldName.equals(newName))	{
503
			if(debug)	{
504
				System.out.println("PluginMessages.renameKey(): no changes, skipped key: " + oldName + " = " + newName);
505
			}
506
			return;
507
		}
508

  
509
		
478 510
		messageKeys.remove(oldName);
479 511
		messageKeys.add(newName);
480 512
		

Formats disponibles : Unified diff