Révision 1227

tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/NormalizeKeys.java (revision 1227)
18 18
	
19 19
	public static boolean debug = true;
20 20
	
21
	/**
22
	 * Keys matching this regex will be preserved.
23
	 */
24
	public static String preserve = "^(common_|error_|info_).*$"; 
21 25
	
22
	
26
	/**
27
	 * 
28
	 * @param messages
29
	 * @return
30
	 */
23 31
	public static BiHashMap<String, String> normalize(BiHashMap<String, String> messages)	{
24 32
		
25 33
		for (String key : messages.getKeys()) {
34
			String value = messages.get(key);
35
			
36
			// already formatted message
37
			if(key.matches(preserve))	{
38
				System.err.println("NormalizeKeys.normalize(): warning: skipped: " + key + " = " + value);
39
				continue;
40
			}
41
			// empty message
42
			else if(value.length() == 0)	{
43
				System.err.println("NormalizeKeys.normalize(): warning: empty string for key: " + key); 
44
				continue;
45
			}
46
			
26 47
			messages.put(normalize(messages.get(key)), messages.get(key));
27 48
		}
28 49
		
29 50
		return messages;
30 51
	}
31 52
	
32
	/**
33
	 * 
34
	 * @param strings
35
	 * @return
36
	 */
37
	public static HashSet<String> normalize(HashSet<String> strings)	{
38
		for (String str : strings) {
39
			if(debug)	{
40
				System.out.println(str);
41
				System.out.println("   => " + normalize(str));
42
			}
43
		}
44
		
45
		return strings;
46
	}
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
//	}
47 68
	
48 69
	
49 70
	/**
......
101 122
	 */
102 123
	public static void main(String[] args) {
103 124

  
125
		System.out.println("NormalizeKeys.main(): starting process...");
126
		
104 127
		// tests
105 128
		System.out.println(NLS.bind("lol {0}", 1));
106 129
		
......
108 131
		messages.put("Convert5To6_46", "Error while computing."); 
109 132
		messages.put("Convert5To6_46", "** Error: the connexion to the server failed: wrong port format");
110 133
		messages.put("Convert5To6_6", "** Error: ''{0}'' corpus directory is not conformant to TXM corpus binary format: corpus skipped.");
134
		messages.put("common_lowestFrequency", "Lowest frequency");
111 135
		messages.put("Convert5To6_27", "T");
112 136
		messages.put("Convert5To6_28", "");
113 137
		messages = normalize(messages);
114
		System.out.println("NormalizeKeys.main()");
138

  
139
		System.out.println("NormalizeKeys.main(): terminated.");
115 140
		
116 141
//		HashSet<String> strings = new HashSet<String>();
117 142
//		strings.add("Error while computing.");

Formats disponibles : Unified diff