A simplified approach to the culture and internationalization of JSF

Source: Internet
Author: User
Tags add config locale resource root directory
Js| Chinese for a variety of Java applications, the internationalization of the problem will always bring some trouble to our non-English users, as in JSF, in practice, encountered a series of difficult to solve the problem, the final solution to most of the problems, but also completed a small project can be run, I take some of my experience and share it with you, hoping to get people to take some detours in these places.

Internationalization in Java is supported by the Java.util.Locale class, the corresponding code in Chinese is "en", so we need to do some simple configuration in our faces-config.xml in order to use Chinese in JSF, and add support for Chinese. Of course, if you need to support more languages, add a few more <supported-locale> on it.



Resource

en
en



This defines a <message-bundle> resource </message-bundle> that refers to the location and file name of the resource file. Here we put the resource file in the source root directory named Resource.properties, this is a resource file in English, and another resource file containing Chinese information is named Resource_zh.properties.

Next, we can add the resource information we need in these resource files. We recommend you an Eclipse plug-in to write our resource file, which is called Eclipse ResourceBundle Editor Plugin, we can easily write in Chinese information, it will automatically convert to UTF-8 encoded information, Everyone can go to this place to download this plugin http://resourcebundleeditor.com/ess/rbe/home.do. It's easy to use, and there's no more to say.

Before you use these resources in your JSP files, you need to add these things:

<%@ page contenttype= "Text/html;charset=utf-8"%>


Add in the head of the HTML:


Below, we can bind and use these resource information in our pages:

To load the resource file before use, use this tag:

 
I have an alias for the message here, and I can use this alias to messages the resource file later.

For example, I use


Is it possible to use it? But don't worry, use is, if you use Tiles in JSF, there will be some problems, if we use the
In this way, everything is normal, and using Tiles is no problem.

Today, a friend asked me about JavaScript in Chinese garbled problem, I found in my JSP a piece of code to take out to see:


In this way, the Chinese inside can be normal display, below I give you some suggestions, I hope to have some help.

1. All text information is written in the resource file, using this information by referencing its alias;

2. All Chinese to convert to UTF-8 encoding, you can use the Eclipse ResourceBundle Editor plugin to solve;
 
3. The page encoding method is defined as UTF-8, and do not use its default values.
 
Of course, it's just a little bit of experience I've accumulated in use, hope to have a little help to everyone, if you find anything incorrect please enlighten us, if better solution, also take out and share it, because our sharing may save more time for everyone.

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.