How to handle multiple languages in java?

☆樱花仙子☆ 提交于 2019-12-04 13:53:31

问题


I am writing a program use jsp and java, how can i use properties files to support multiple languages ? and by the way, there are always something like \u4345, What's this ? How do they come ?


回答1:


For the multiple languages, check out the ResourceBundle class.

About the \u4345, this is one of the dark and very annoying legacy corners of Java. The property files need to be in ASCII, so that all non-ASCII characters need to encoded as \uxxxx (their Unicode value). You can convert a file to use this encoding with the native2ascii command line tool. If you are using an IDE or a build tool, there should be an option to invoke this automatically.

If the property file is something you have full control over yourself, you can starting from Java6 also use UTF-8 (or any other character set) directly in the property file, and specify that encoding when you load it:

// new in Java6
props.load(new InputStreamReader(new FileInputStream(file), 'UTF-8'));

Again, this only works if you load the Properties yourself, not if someone else does it, such as a ResourceBundle (used for internationalization).




回答2:


there is an entire tutorial on http://java.sun.com/docs/books/tutorial/i18n/index.html

This specifies and explains about anything you need to know.




回答3:


The Java tutorial on i18n has been mentioned already by Peter. If you are building JSPs you probably want to look at the JSTL which basically allows you to use the functionality of ResourceBundle through JSP tags.



来源:https://stackoverflow.com/questions/1270067/how-to-handle-multiple-languages-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!