Java invoke Native2ascii to parse properties file

Source: Internet
Author: User
Tags stringbuffer

Recently in the implementation of Liferay found Liferay find this translation is really bad, a lot of things translated simply Dog, such as the forum topic translated into "thread", the virtual host translated as "real owner", or there is no translation. A look is a person who has no experience in program development and may be a Taiwanese person.

No way can only do for Liferay to do the Han chemical.

Liferay resource file is still good, basically all the messages in the interface are placed in the resource file. The specific Chinese is: portal-impl/content the following language_zh_cn.properties and Language_zh_CN.properties.native. The previous one is a Unicode string, and the latter one is Chinese. It is OK to translate the contents of the native file first, and then convert the Chinese characters to Unicode to replace the previous one.

Can native file actually have more than 3,000, if all hand through native2asccii to convert words, it is a nightmare. Because I am lazy, of course, to use lazy way. Wrote a Java program called Native2ascii to get it done.

The code is as follows:

Import Java.io.FileInputStream;
Import Java.io.FileWriter;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.io.OutputStream;
Import java.io.UnsupportedEncodingException;
Import Java.util.Iterator;
Import java.util.Properties;

/** */ /**
* @author Smilingleo e-mail:liuwei.dt@gmail.com
* @version created Time:2007-11-2 11:37:55 class Description:
*/

public class Native2ascii ... {
static String Java_bin_path = "C:/java/jdk1.5/bin";

Public Native2ascii () ... {

}

Public Properties getProperties (String filename) throws IOException ... {
Properties P = new properties ();
ClassLoader cl = This.getclass (). getClassLoader ();
FileInputStream input;
input = new FileInputStream (filename);
P.load (input);
return p;

}
public string getunicodestring (string value) ... {

StringBuffer TEMPSB = new StringBuffer ();
Try ... {
Process Pro = Runtime.getruntime (). EXEC (
Java_bin_path + "/native2ascii.exe");
OutputStream out = Pro.getoutputstream ();
Out.write (Value.getbytes ());
Out.flush ();
Out.close ();
InputStreamReader child_in = new InputStreamReader (Pro.getinputstream ());

int C;
while ((c = child_in.read ())!=-1) ... {
Tempsb.append ((char) c);
}

catch (Unsupportedencodingexception e) ... {
E.printstacktrace ();
catch (IOException ex) ... {
Ex.printstacktrace ();
}

return tempsb.tostring ();
}

/** *//**
* @param args
*/
public static void Main (string[] args) ... {
String sourcefile = "Language_zh_cn.properties";
String targetfile = "Target.properties";
if (args.length!= 2) ... {
System.out.println ("Usage:java native2ascii <source properties filename> <target filename>" +
&n

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.