Révision 1263

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

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.IOException;
6
import java.io.UnsupportedEncodingException;
7
import java.util.LinkedHashMap;
8
import java.util.LinkedHashSet;
9

  
10
import org.txm.rcp.translate.i18n.PluginMessages;
11
import org.txm.rcp.translate.i18n.WorkspaceMessagesManager;
12
import org.txm.utils.BiHashMap;
13

  
14
public class FindUnusedTranslations {
15
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
16
		WorkspaceMessagesManager wmm = new WorkspaceMessagesManager();
17
		LinkedHashMap<File, PluginMessages> h = wmm.getPluginMessages();
18

  
19
		String langs[] = {"", "_fr", "_ru"};
20

  
21
		for (File project : h.keySet()) {
22

  
23
			PluginMessages messages = h.get(project);
24
			LinkedHashSet<String> keys = messages.getMessageKeys();
25
			for (String lang : langs) {
26
				BiHashMap<String, String> lmessages = messages.getMessagesForLang(lang);
27
				if (lmessages == null) continue;
28
				
29
				for (String k : lmessages.getKeys()) {
30
					if (!keys.contains(k)) {
31
						System.out.println(" Remove key="+k);
32
						lmessages.removeByKey(k);
33
					}
34
				}
35
			}
36
			
37
			// messages.saveChanges();
38
		}
39
	}
40
}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/FindMissingTranslations.java (revision 1263)
1
package org.txm.rcp.translate.devtools;
2

  
3
public class FindMissingTranslations {
4

  
5
}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/RemoveUnusedTranslations.java (revision 1263)
1
package org.txm.rcp.translate.devtools;
2

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.IOException;
6
import java.io.UnsupportedEncodingException;
7
import java.util.LinkedHashMap;
8
import java.util.LinkedHashSet;
9

  
10
import org.txm.rcp.translate.i18n.PluginMessages;
11
import org.txm.rcp.translate.i18n.WorkspaceMessagesManager;
12
import org.txm.utils.BiHashMap;
13

  
14
public class RemoveUnusedTranslations {
15
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
16
		WorkspaceMessagesManager wmm = new WorkspaceMessagesManager();
17
		LinkedHashMap<File, PluginMessages> h = wmm.getPluginMessages();
18

  
19
		String langs[] = {"", "_fr", "_ru"};
20

  
21
		for (File project : h.keySet()) {
22

  
23
			PluginMessages messages = h.get(project);
24
			LinkedHashSet<String> keys = messages.getMessageKeys();
25
			for (String lang : langs) {
26
				BiHashMap<String, String> lmessages = messages.getMessagesForLang(lang);
27
				if (lmessages == null) continue;
28
				
29
				for (String k : lmessages.getKeys()) {
30
					if (!keys.contains(k)) {
31
						System.out.println(" Remove key="+k);
32
						lmessages.removeByKey(k);
33
					}
34
				}
35
			}
36
			
37
			// messages.saveChanges();
38
		}
39
	}
40
}
0 41

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

  
3
/**
4
 * Test properties files :
5
 * - no duplicated key
6
 * - no empty message
7
 * 
8
 * @author mdecorde
9
 *
10
 */
11
public class FindBugsInPropertiesFiles {
12

  
13
}
0 14

  
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1263)
18 18
 *
19 19
 */
20 20
public class NormalizeKeys {
21
	
21

  
22 22
	/**
23 23
	 * Debug state.
24 24
	 */
25 25
	protected boolean debug = false;
26
	
26

  
27 27
	/**
28 28
	 * Keys matching this REGEX will be preserved.
29 29
	 */
......
48 48
	public int normalize(PluginMessages pmManager)	{
49 49

  
50 50
		BiHashMap<String, String> messages = pmManager.getMessagesForDefaultLang();
51
		
51

  
52 52
		ArrayList<String> keys = new ArrayList<String>(pmManager.getMessageKeys());
53
		
53

  
54 54
		int n = 0;
55 55
		for (String key : keys) {
56 56
			String value = messages.get(key);
......
68 68
				if (debug)  System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); 
69 69
				continue;
70 70
			}
71
			
71

  
72 72
			String newKeyOrig = normalize(messages.get(key));
73
			String newKey = ""+newKeyOrig;
74
			int c = 2;
75
			while (pmManager.getMessageKeys().contains(newKey)) {
76
				newKey += newKeyOrig+"_"+(c++);
73

  
74
			if (value.equals(messages.get(newKeyOrig))) { // the newKey Value == the value
75
				//A=hello world
76
				//B=hello world
77
				// rename A -> helloWorld
78
				//B -> helloWorld SAUF QUE helloWorld existe ET meme valeur que valeur(B) valeur(helloWorld)
79

  
80
				pmManager.removeKey(key); // remove the old key
81
			} else {
82
				// A=hello world
83
				// B=hello world!
84
				// A et B n'ont pas la meme clé
85
				
86
				String newKey = ""+newKeyOrig;
87
				int c = 2;
88
				while (pmManager.getMessageKeys().contains(newKey)) {
89
					newKey += newKeyOrig+"_"+(c++);
90
				}
91

  
92
				pmManager.renameKey(key, newKey);
77 93
			}
78
			
79
			pmManager.renameKey(key, newKey);
80
			
81 94
			n++;
82 95
		}
83
		
96

  
84 97
		return n;
85 98
	}
86
	
87
	
88
	
89
//	/**
90
//	 * Normalizes the keys of the specified messages map.
91
//	 * @param messages
92
//	 * @return
93
//	 */
94
//	public BiHashMap<String, String> normalize(BiHashMap<String, String> messages)	{
95
//		
96
//		for (String key : messages.getKeys()) {
97
//			String value = messages.get(key);
98
//			
99
//			// already formatted message
100
//			if(key.matches(preserve))	{
101
//				System.err.println("NormalizeKeys.normalize(): warning: skipped: " + key + "=" + value);
102
//				continue;
103
//			}
104
//			// empty message
105
//			else if(value.length() == 0)	{
106
//				System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); 
107
//				continue;
108
//			}
109
//			
110
//			messages.put(normalize(messages.get(key)), messages.get(key));
111
//			//messages.removeByKey(key);
112
//		}
113
//		
114
//		return messages;
115
//	}
116
//	
117 99

  
100

  
101

  
102
	//	/**
103
	//	 * Normalizes the keys of the specified messages map.
104
	//	 * @param messages
105
	//	 * @return
106
	//	 */
107
	//	public BiHashMap<String, String> normalize(BiHashMap<String, String> messages)	{
108
	//		
109
	//		for (String key : messages.getKeys()) {
110
	//			String value = messages.get(key);
111
	//			
112
	//			// already formatted message
113
	//			if(key.matches(preserve))	{
114
	//				System.err.println("NormalizeKeys.normalize(): warning: skipped: " + key + "=" + value);
115
	//				continue;
116
	//			}
117
	//			// empty message
118
	//			else if(value.length() == 0)	{
119
	//				System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); 
120
	//				continue;
121
	//			}
122
	//			
123
	//			messages.put(normalize(messages.get(key)), messages.get(key));
124
	//			//messages.removeByKey(key);
125
	//		}
126
	//		
127
	//		return messages;
128
	//	}
129
	//	
130

  
118 131
	/**
119 132
	 * Normalizes the specified string.
120 133
	 * @param str
......
125 138
		if(debug)	{
126 139
			System.out.println("NormalizeKeys.normalize(): normalizing: " + str);
127 140
		}
128
		
141

  
129 142
		str = str.replaceAll("[^a-zA-Z0-9 ]", "").trim();
130
		
143

  
131 144
		// empty string
132 145
		if(str.length() == 0)	{
133 146
			System.err.println("NormalizeKeys.normalize(): warning: empty string.");
134 147
		}
135 148
		else	{
136
			
149

  
137 150
			String[] words = str.split(" ");
138 151
			str = "";
139 152
			for (int i = 0; i < words.length; i++) {
......
154 167
					// nothing to do
155 168
				}
156 169
			}
157
			
170

  
158 171
			// uncapitalize first letter
159 172
			String tmpString = str.substring(0, 1).toLowerCase();
160 173
			try {
......
170 183
		if(debug)	{
171 184
			System.out.println("   => " + str);
172 185
		}
173
		
186

  
174 187
		return str;
175 188
	}
176
	
189

  
177 190
	/**
178 191
	 * 
179 192
	 * @param args
......
183 196
	 */
184 197
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
185 198

  
186
//		try {
187
//			System.out.println("NormalizeKeys.main(): starting process...");
188
//			
189
//			File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
190
//			File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
191
//			
192
//			PluginMessages pmManager = new PluginMessages(projectFile, messageFile, false);
193
//			NormalizeKeys keysNormalizer = new NormalizeKeys(true);
194
//			
195
//			// tests
196
//			keysNormalizer.normalize(pmManager);
197
//
198
//			//pmManager.dump(pmManager.getMessagesForMainLang());
199
//			pmManager.dumpKeysReplacements();
200
//			
201
//			System.out.println("NormalizeKeys.main(): number of keys: " + pmManager.getMessageKeys().size() + ".");
202
//			System.out.println("NormalizeKeys.main(): number of replacements to do: " + pmManager.getKeyModifications().size() + ".");
203
//
204
//			System.out.println("NormalizeKeys.main(): terminated.");
205
//			
206
//		}
207
//		catch (UnsupportedEncodingException e) {
208
//			// TODO Auto-generated catch block
209
//			e.printStackTrace();
210
//		}
211
//		catch (FileNotFoundException e) {
212
//			// TODO Auto-generated catch block
213
//			e.printStackTrace();
214
//		}
215
//		catch (IOException e) {
216
//			// TODO Auto-generated catch block
217
//			e.printStackTrace();
218
//		}
219
		
199
		//		try {
200
		//			System.out.println("NormalizeKeys.main(): starting process...");
201
		//			
202
		//			File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
203
		//			File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
204
		//			
205
		//			PluginMessages pmManager = new PluginMessages(projectFile, messageFile, false);
206
		//			NormalizeKeys keysNormalizer = new NormalizeKeys(true);
207
		//			
208
		//			// tests
209
		//			keysNormalizer.normalize(pmManager);
210
		//
211
		//			//pmManager.dump(pmManager.getMessagesForMainLang());
212
		//			pmManager.dumpKeysReplacements();
213
		//			
214
		//			System.out.println("NormalizeKeys.main(): number of keys: " + pmManager.getMessageKeys().size() + ".");
215
		//			System.out.println("NormalizeKeys.main(): number of replacements to do: " + pmManager.getKeyModifications().size() + ".");
216
		//
217
		//			System.out.println("NormalizeKeys.main(): terminated.");
218
		//			
219
		//		}
220
		//		catch (UnsupportedEncodingException e) {
221
		//			// TODO Auto-generated catch block
222
		//			e.printStackTrace();
223
		//		}
224
		//		catch (FileNotFoundException e) {
225
		//			// TODO Auto-generated catch block
226
		//			e.printStackTrace();
227
		//		}
228
		//		catch (IOException e) {
229
		//			// TODO Auto-generated catch block
230
		//			e.printStackTrace();
231
		//		}
232

  
220 233
		NormalizeKeys keysNormalizer = new NormalizeKeys(false);
221
		
234

  
222 235
		WorkspaceMessagesManager wmm = new WorkspaceMessagesManager();
223 236
		for (PluginMessages pm : wmm.getPluginMessages().values()) {
224 237
			keysNormalizer.normalize(pm);
225 238
		}
226
		
239

  
227 240
		//wmm.saveKeyModificationsInSources();
228 241
	}
229 242
}
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java (revision 1263)
66 66

  
67 67

  
68 68
	/**
69
	 * Global REGEX containing all keys to later use for search in files.
69
	 * TODO Global REGEX containing all keys to later use for search in files.
70 70
	 */
71 71
	protected Pattern keysGlobalREGEX = Pattern.compile("...");
72 72

  

Formats disponibles : Unified diff