Révision 1232

tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/ImportFromOneFile.java (revision 1232)
68 68
			}
69 69
			total_update += update;
70 70
		}
71
		
72
		for (File project : h.keySet()) {
73
			//h.get(project).saveChanges();
74
		}
75
		
71 76
		if (total_update == 0) {
72 77
			System.out.println("Done, no update done.");
73 78
		} else {
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/devtools/FindUnusedTranslations.java (revision 1232)
1 1
package org.txm.rcp.translate.devtools;
2 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

  
3 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();
4 18

  
5
}
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/FindMessagesToBind.java (revision 1232)
1
package org.txm.rcp.translate.devtools;
2

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

  
11
import org.txm.rcp.translate.i18n.PluginMessages;
12
import org.txm.rcp.translate.i18n.WorkspaceMessagesManager;
13
import org.txm.utils.DeleteDir;
14
import org.txm.utils.io.IOUtils;
15

  
16
/**
17
 * 
18
 * Finds duplicated messages in all core and rcp plug-ins.
19
 * Merges them in a new key and move them to org.txm.core or org.txm.rcp.
20
 *
21
 */
22
public class FindMessagesToBind {
23

  
24
	private void processSourceFile(File sourceFile) {
25

  
26
		//BufferedReader reader = IOUtils.getReader(sourceFile)
27
		//String line = reader.readLine();
28
		boolean ignore = false;
29
		ArrayList<String> lines = IOUtils.getLines(sourceFile, "UTF-8");
30
		
31
		for (String line : lines) {
32
			//println ""+line
33
			String l = line.trim();
34

  
35
			if (ignore) {
36
				if (l.startsWith("*/") || l.endsWith("*/")) {
37
					ignore = false;
38
				}
39
			} else {
40
				if (l.startsWith("//") || l.startsWith("@")) {
41
					// ignore
42
				} else if (l.startsWith("/*")) {
43
					ignore = true;
44
					if (l.endsWith("*/")) ignore=false;
45
				} else {
46
					ArrayList<String> strings = getLineStrings(l);
47
					if (strings.size() > 0) {
48
						System.out.println(strings);
49
					}
50
				}
51
			}
52

  
53
		}
54
	}
55

  
56
	private ArrayList<String> getLineStrings(String l) {
57
		ArrayList<String> strings = new ArrayList<String>();
58
		boolean inS = false;
59
		int start = 0;
60
		int comment = 0;
61
		for(int i = 0 ; i < l.length() ; i++) {
62
			String c = ""+l.charAt(i);
63
			if (inS) {
64
				comment = 0;
65
				if (c.equals("\\")) {
66
					i++;
67
				} else if (c.equals("\"")) {
68
					inS = false;
69
					strings.add(l.substring(start, i+1));
70
				}
71
			} else {
72
				if (c.equals("\"")) {
73
					inS = true;
74
					start = i;
75
					comment = 0;
76
				} else if (c.equals("/")) {
77
					comment++;
78
					if (comment == 2) break;
79
				} else {
80
					comment = 0;
81
				}
82
			}
83
		}
84
		return strings;
85
	}
86

  
87
	public void run() throws UnsupportedEncodingException, FileNotFoundException, IOException {
88
		WorkspaceMessagesManager wmm = new WorkspaceMessagesManager();
89
		LinkedHashMap<File, PluginMessages> h = wmm.getPluginMessages();
90

  
91
		for (File project : h.keySet()) {
92

  
93
			System.out.println("Project: "+project);
94

  
95
			File srcDir = new File(project, "src/java");
96
			if (!srcDir.exists())  srcDir = new File(project, "src");
97
			if (!srcDir.exists()) continue; // no Java sources
98

  
99
			ArrayList<File> files = DeleteDir.scanDirectory(srcDir, true);
100
			for (File javaFile : files) {
101

  
102
				if (!javaFile.getName().endsWith(".java")) continue;
103
				if (javaFile.getName().endsWith("Messages.java")) continue;
104

  
105
				System.out.println(" File: "+javaFile);
106
				processSourceFile(javaFile);
107
			}
108
		}
109
	}
110

  
111
	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
112

  
113
		new FindMessagesToBind().run();
114
	}
115
}
0 116

  
tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java (revision 1232)
70 70
		}
71 71
	}
72 72
	
73
	public BiHashMap<String, String> getMessagesForLang(String lang) {
74
		File p = new File(messageFile.getParentFile(), "messages"+lang+".properties");
75
		return langs.get(p);
76
	}
77
	
73 78
	public void put(String lang, String key, String message) {
74 79
		messageKeys.add(key);
75 80
		
......
138 143
//		return missing
139 144
//	}
140 145
	
141
	public void saveChanges() throws UnsupportedEncodingException, FileNotFoundException {
146
	public void saveChanges() throws IOException {
142 147

  
143 148
		//Write prop File
144 149
		for (File propFile : langs.keySet()) {
145
			String name = propFile.getName();
146
			if (!name.endsWith(".properties")) continue;
150

  
151
			Properties props = new Properties();
152
			BiHashMap<String, String> h = langs.get(propFile);
153
			for (String k : h.getKeys()) {
154
				props.setProperty(k, h.get(k));
155
			}
147 156
			
148
			File oldFile = new File(propFile.getParentFile(), propFile.getName()+".cpy");
149
			propFile.renameTo(oldFile);
157
			if (propFile.exists()) {
158
				File oldFile = new File(propFile.getParentFile(), propFile.getName()+".old");
159
				if (oldFile.exists()) {
160
					oldFile.delete();
161
				}
162
				propFile.renameTo(oldFile);
163
			}
150 164
			
151
			Properties props = new Properties();
165
			props.store(IOUtils.getWriter(propFile, encoding),  "TXM messages generated by the PluginMessages class");
152 166
		}
153 167
		
154 168
		// write message File
155 169
		if (messageFile == null) return;
156 170
		
157
		File oldFile2 = new File(messageFile.getParentFile(), messageFile.getName()+".cpy");
171
		File oldFile2 = new File(messageFile.getParentFile(), messageFile.getName()+".old");
158 172
		messageFile.renameTo(oldFile2); // back up
159 173
		
160 174
		String className = getMessageClassName();

Formats disponibles : Unified diff