提交 9a9186a2 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 be1fb4db
...@@ -22,4 +22,5 @@ public class SortedProperties extends Properties { ...@@ -22,4 +22,5 @@ public class SortedProperties extends Properties {
Collections.sort(v); Collections.sort(v);
return v.elements(); return v.elements();
} }
} }
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
*/ */
package org.h2.tools.i18n; package org.h2.tools.i18n;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
...@@ -14,10 +11,8 @@ import java.io.FileReader; ...@@ -14,10 +11,8 @@ 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.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
...@@ -286,7 +281,7 @@ public class PrepareTranslation { ...@@ -286,7 +281,7 @@ public class PrepareTranslation {
// } // }
} }
new File(target + "/" + MAIN_LANGUAGE).mkdirs(); new File(target + "/" + MAIN_LANGUAGE).mkdirs();
storeProperties(prop, target + "/" + MAIN_LANGUAGE + "/" + documentName + "_" + MAIN_LANGUAGE + ".properties"); PropertiesToUTF8.storeProperties(prop, target + "/" + MAIN_LANGUAGE + "/" + documentName + "_" + MAIN_LANGUAGE + ".properties");
String t = template.toString(); String t = template.toString();
if(templateIsCopy && !t.equals(xml)) { if(templateIsCopy && !t.equals(xml)) {
for(int i=0; i<Math.min(t.length(), xml.length()); i++) { for(int i=0; i<Math.min(t.length(), xml.length()); i++) {
...@@ -340,12 +335,12 @@ public class PrepareTranslation { ...@@ -340,12 +335,12 @@ public class PrepareTranslation {
Properties p = FileUtils.loadProperties(main.getAbsolutePath()); Properties p = FileUtils.loadProperties(main.getAbsolutePath());
Properties base = FileUtils.loadProperties(baseDir + "/" Properties base = FileUtils.loadProperties(baseDir + "/"
+ main.getName()); + main.getName());
storeProperties(p, main.getAbsolutePath()); PropertiesToUTF8.storeProperties(p, main.getAbsolutePath());
for (int i = 0; i < translations.size(); i++) { for (int i = 0; i < translations.size(); i++) {
File trans = (File) translations.get(i); File trans = (File) translations.get(i);
prepare(p, base, trans); prepare(p, base, trans);
} }
storeProperties(p, baseDir + "/" + main.getName()); PropertiesToUTF8.storeProperties(p, baseDir + "/" + main.getName());
} }
private static void prepare(Properties main, Properties base, File trans) private static void prepare(Properties main, Properties base, File trans)
...@@ -393,27 +388,6 @@ public class PrepareTranslation { ...@@ -393,27 +388,6 @@ public class PrepareTranslation {
p.remove(key); p.remove(key);
} }
} }
storeProperties(p, trans.getAbsolutePath()); PropertiesToUTF8.storeProperties(p, trans.getAbsolutePath());
}
static void storeProperties(Properties p, String fileName)
throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
p.store(out, null);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
LineNumberReader r = new LineNumberReader(reader);
FileWriter w = new FileWriter(fileName);
PrintWriter writer = new PrintWriter(new BufferedWriter(w));
while (true) {
String line = r.readLine();
if (line == null) {
break;
}
if (!line.startsWith("#")) {
writer.println(line);
}
}
writer.close();
} }
} }
...@@ -4,16 +4,27 @@ ...@@ -4,16 +4,27 @@
*/ */
package org.h2.tools.i18n; package org.h2.tools.i18n;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.Enumeration;
import java.util.Properties;
import org.h2.tools.code.CheckTextFiles; import org.h2.tools.code.CheckTextFiles;
import org.h2.tools.indexer.HtmlConverter; import org.h2.tools.indexer.HtmlConverter;
import org.h2.util.FileUtils;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.SortedProperties;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
public class PropertiesToUTF8 { public class PropertiesToUTF8 {
...@@ -22,6 +33,49 @@ public class PropertiesToUTF8 { ...@@ -22,6 +33,49 @@ public class PropertiesToUTF8 {
convert("bin/org/h2/server/web/res", "."); convert("bin/org/h2/server/web/res", ".");
} }
private static void propertiesToTextUTF8(String source, String target) throws Exception {
Properties prop = FileUtils.loadProperties(source);
FileOutputStream out = new FileOutputStream(target);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, "UTF-8"));
// keys is sorted
for(Enumeration en = prop.keys(); en.hasMoreElements(); ) {
String key = (String) en.nextElement();
String value = prop.getProperty(key, null);
writer.println("@" + key);
writer.println(value);
writer.println();
}
writer.close();
}
private static void textUTF8ToProperties(String source, String target) throws Exception {
LineNumberReader reader = new LineNumberReader(new InputStreamReader(new FileInputStream(source), "UTF-8"));
Properties prop = new SortedProperties();
StringBuffer buff = new StringBuffer();
String key = null;
while(true) {
String line = reader.readLine().trim();
if(line == null) {
break;
}
if(line.startsWith("@")) {
if(key != null) {
prop.setProperty(key, buff.toString());
buff.setLength(0);
}
} else {
if(buff.length() > 0) {
buff.append(System.getProperty("line.separator"));
}
buff.append(line);
}
}
if(key != null) {
prop.setProperty(key, buff.toString());
}
storeProperties(prop, target);
}
private static void convert(String source, String target) throws Exception { private static void convert(String source, String target) throws Exception {
File[] list = new File(source).listFiles(); File[] list = new File(source).listFiles();
for(int i=0; list != null && i<list.length; i++) { for(int i=0; list != null && i<list.length; i++) {
...@@ -53,4 +107,25 @@ public class PropertiesToUTF8 { ...@@ -53,4 +107,25 @@ public class PropertiesToUTF8 {
} }
} }
static void storeProperties(Properties p, String fileName)
throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
p.store(out, null);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
LineNumberReader r = new LineNumberReader(reader);
FileWriter w = new FileWriter(fileName);
PrintWriter writer = new PrintWriter(new BufferedWriter(w));
while (true) {
String line = r.readLine();
if (line == null) {
break;
}
if (!line.startsWith("#")) {
writer.println(line);
}
}
writer.close();
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论