提交 1556258b authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 81c34acc
...@@ -27,6 +27,7 @@ public class XMLParser { ...@@ -27,6 +27,7 @@ public class XMLParser {
private int index; private int index;
private int eventType; private int eventType;
private String currentText; private String currentText;
private String currentToken;
private String prefix, localName; private String prefix, localName;
private String[] attributeValues = new String[3]; private String[] attributeValues = new String[3];
private int currentAttribute; private int currentAttribute;
...@@ -83,18 +84,15 @@ public class XMLParser { ...@@ -83,18 +84,15 @@ public class XMLParser {
private void read() { private void read() {
currentText = null; currentText = null;
currentAttribute = 0; currentAttribute = 0;
int currentStart = index; int tokenStart = index, currentStart = index;
int ch = readChar(); int ch = readChar();
if (ch < 0) { if (ch < 0) {
eventType = END_DOCUMENT; eventType = END_DOCUMENT;
return; } else if (ch == '<') {
}
if (ch == '<') {
currentStart = index; currentStart = index;
ch = readChar(); ch = readChar();
if (ch < 0) { if (ch < 0) {
eventType = ERROR; eventType = ERROR;
return;
} else if (ch == '?') { } else if (ch == '?') {
eventType = PROCESSING_INSTRUCTION; eventType = PROCESSING_INSTRUCTION;
currentStart = index; currentStart = index;
...@@ -108,10 +106,12 @@ public class XMLParser { ...@@ -108,10 +106,12 @@ public class XMLParser {
} }
} }
if(xml.substring(currentStart).startsWith("xml")) { if(xml.substring(currentStart).startsWith("xml")) {
int back = tokenStart;
read(); read();
return; tokenStart = back;
} else {
currentText = xml.substring(currentStart, index - 1);
} }
currentText = xml.substring(currentStart, index - 1);
} else if (ch == '!') { } else if (ch == '!') {
ch = readChar(); ch = readChar();
if (ch == '-') { if (ch == '-') {
...@@ -224,6 +224,7 @@ public class XMLParser { ...@@ -224,6 +224,7 @@ public class XMLParser {
} }
} }
} else { } else {
// TODO need to replace &#xx;?
eventType = CHARACTERS; eventType = CHARACTERS;
while (true) { while (true) {
ch = readChar(); ch = readChar();
...@@ -236,6 +237,7 @@ public class XMLParser { ...@@ -236,6 +237,7 @@ public class XMLParser {
} }
currentText = xml.substring(currentStart, index); currentText = xml.substring(currentStart, index);
} }
currentToken = xml.substring(tokenStart, index);
} }
private void readAttributeValues() { private void readAttributeValues() {
...@@ -302,6 +304,7 @@ public class XMLParser { ...@@ -302,6 +304,7 @@ public class XMLParser {
if(endElement) { if(endElement) {
endElement = false; endElement = false;
eventType = END_ELEMENT; eventType = END_ELEMENT;
currentToken = "";
} else { } else {
read(); read();
} }
...@@ -324,6 +327,10 @@ public class XMLParser { ...@@ -324,6 +327,10 @@ public class XMLParser {
public String getText() { public String getText() {
return currentText; return currentText;
} }
public String getToken() {
return currentToken;
}
public int getAttributeCount() { public int getAttributeCount() {
return currentAttribute / 3; return currentAttribute / 3;
......
...@@ -8,12 +8,16 @@ import java.io.BufferedWriter; ...@@ -8,12 +8,16 @@ import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
...@@ -28,14 +32,15 @@ public class PrepareTranslation { ...@@ -28,14 +32,15 @@ public class PrepareTranslation {
private static final String DELETED_PREFIX = "~"; private static final String DELETED_PREFIX = "~";
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String baseDir = "src/tools/org/h2/tools/i18n"; int todoSwitchOn;
String path; // String baseDir = "src/tools/org/h2/tools/i18n";
path = "src/main/org/h2/res"; // String path;
prepare(baseDir, path); // path = "src/main/org/h2/res";
path = "src/main/org/h2/server/web/res"; // prepare(baseDir, path);
prepare(baseDir, path); // path = "src/main/org/h2/server/web/res";
// prepare(baseDir, path);
int todoAllowTranslateHtmlFiles; int todoAllowTranslateHtmlFiles;
// extract("src/docsrc/html"); extract("src/docsrc/html");
} }
private static void extract(String dir) throws Exception { private static void extract(String dir) throws Exception {
...@@ -65,28 +70,57 @@ public class PrepareTranslation { ...@@ -65,28 +70,57 @@ public class PrepareTranslation {
return false; return false;
} }
private static void extract(HashSet set, String documentName, File f) throws Exception { private static void extract(HashSet already, String documentName, File f) throws Exception {
String xml = IOUtils.readStringAndClose(new FileReader(f), -1); String xml = IOUtils.readStringAndClose(new InputStreamReader(new FileInputStream(f), "UTF-8"), -1);
// Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f.getName()), "UTF-8"));
XMLParser parser = new XMLParser(xml); XMLParser parser = new XMLParser(xml);
StringBuffer buff = new StringBuffer();
boolean translate = true; boolean translate = true;
String tag = "";
for(int i=0;;) { for(int i=0;;) {
int event = parser.next(); int event = parser.next();
String s = parser.getToken();
// writer.write(s);
if(event == XMLParser.END_DOCUMENT) { if(event == XMLParser.END_DOCUMENT) {
break; break;
} else if(event == XMLParser.CHARACTERS) { } else if(event == XMLParser.CHARACTERS) {
String text = parser.getText().trim(); String text = parser.getText();
if(translate && !set.contains(text) && isText(text)) { if(translate) {
System.out.println(documentName + "_" + i++ ); if("p".equals(tag) || "li".equals(tag) || "a".equals(tag) ||
System.out.println(text); "td".equals(tag) || "th".equals(tag) || "h1".equals(tag) ||
System.out.println(); "h2".equals(tag) || "h3".equals(tag) || "h4".equals(tag)) {
set.add(text); buff.append(text);
} else if(text.trim().length() > 0) {
System.out.println(f.getName() + " invalid wrapper tag for text: " + tag + " text: " + text);
// System.out.println(parser.getRemaining());
}
} }
} else if(event == XMLParser.START_ELEMENT) { } else if(event == XMLParser.START_ELEMENT) {
String name = parser.getName(); String name = parser.getName();
if("code".equals(name) || "pre".equals(name)) { if("pre".equals(name) || "title".equals(name)) {
translate = false; translate = false;
} else if("p".equals(name) || "li".equals(name) || "a".equals(name) ||
"td".equals(name) || "th".equals(name) || "h1".equals(name) ||
"h2".equals(name) || "h3".equals(name) || "h4".equals(name)) {
translate = true;
if("".equals(tag)) {
tag = name;
}
} else if(translate && ("code".equals(name) || "a".equals(name))) {
buff.append(parser.getToken());
} }
} else if(event == XMLParser.END_ELEMENT) { } else if(event == XMLParser.END_ELEMENT) {
String name = parser.getName();
if("pre".equals(name)) {
translate = true;
} else if(tag.equals(name)) {
translate = false;
tag = "";
} else if(translate) {
if("code".equals(name) || "a".equals(name)) {
buff.append(parser.getToken());
}
}
translate = true; translate = true;
} else if(event == XMLParser.DTD) { } else if(event == XMLParser.DTD) {
} else if(event == XMLParser.COMMENT) { } else if(event == XMLParser.COMMENT) {
...@@ -95,6 +129,7 @@ public class PrepareTranslation { ...@@ -95,6 +129,7 @@ public class PrepareTranslation {
throw new Exception("Unexpected event " + eventType + " at " + parser.getRemaining()); throw new Exception("Unexpected event " + eventType + " at " + parser.getRemaining());
} }
} }
// writer.close();
} }
private static void prepare(String baseDir, String path) throws IOException { private static void prepare(String baseDir, String path) throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论