How To Convert East-Asian Character To Unicode In Java

East-Asian character ( Chinese, Japanese, Korean ) is different from the western character. But our web application should be accessed from all over the world. So we should support display those east-Asian characters on the web page correctly.

The solution to resolve the character charset issue is to use Unicode for all languages messages in our web application. So we need to convert the character to Unicode before render them to the client web page.

Java provides the native2ascii command to implement this goal, and eclipse also has a native2ascii plugin that can make the Unicode converter. If you develop a web application with the spring tool suite, it has integrated the native2ascii plugin by default, this article will tell you how to use the above tool to convert the east-Asian character to Unicode in java.

1. Use native2ascii Tool To Convert Character To Unicode.

  1. Save original Chinese words ( 今天天气很好 ) in a file chinese.txt.
  2. Open a terminal and run the native2ascii command. The first argument is the source text file which contains Chinese words, the second argument is the target Unicode character file which will be generated. You should make sure your JDK has been installed correctly, and the JAVA_HOME/bin folder has been added in the system PATH environment variable value for Windows OS.
    192:~ $ native2ascii chinese.txt chinese_unicode.properties
  3. Open the generated text file, you can find below Unicode content.
    \u4eca\u5929\u5929\u6c14\u5f88\u597d

2. Use Eclipse native2ascii Plugin.

  1. There is an eclipse plugin that can help you to convert Chinese words to Unicode directly when you input the words in a .properties file. Follow the below steps to install it.
  2. Open eclipse, click Help —> Eclipse Market Place menu item.
  3. Input the keyword Properties Editor ( or native2ascii ) after the Find: text box, click the Go button to search. Then click the Install button to install it.
  4. After install, you can create the messages.properties file in the java project. Now when you input Chinese, Japanese, or Korean words, they will be converted to Unicode automatically.
  5. If you use Spring Tool Suite to develop a spring web application, it has contains the native2ascii plugin already.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x