You do not need to add any extra initialization labels, or worry about the management inconvenience caused by storing all the multi-language files in a large properties file. All you need to do is use a $ Lang. get tag, or use i18n. with the get method, the problem of multiple languages will be solved elegantly.
Function Summary of multiple languages in easyjweb:
1. Use $ Lang. Get ("attribute name") on the page to display multilingual information.
2. Use i18n. Get ("property name") in the program to obtain information about multiple languages.
3. multi-language attribute information is stored by module, the file name is "module name. properties", stored in the WEB-INF/applicationresources directory.
4. Application. properties indicates the global attribute name. When no specific definition is found in the module, it is automatically searched in the global module.
5. You can use $ Lang. get ("attribute name", "module name") or i18n. get ("attribute name", "module name") calls the attributes of multiple languages of other modules,
6. use $ Lang. getprametermessage ("attribute name", "parameter 1 "... "Parameter n") to the multi-language attribute information with parameters. For example, if the message is "Hello {0}, your brother {1} is waiting for you ." When $ Lange. Get ("message", "William Raym", "Daxia") is used, the following content is output during template synthesis:
Hello William Raym, your brother Daxia is waiting for you.
7. You can also directly use $ Lang. Get ("attribute name", "first parameter", "second parameter.", "nth parameter ").
8. Use the changelocale (string language) method of i18n to directly switch the preferred language of the client to other languages.
9. Open the language directory directly under the default directory of the template, so that the application has multi-language template support.
Do you think this design can work together? If you have more requirements, please submit them.
Download complete example: ftp://ftp1.easyjf.com/easyjweb/demo/i18n.war
Easyjweb official Demo: http://easyjweb.demo.easyjf.com/i18n/user.ejf
The following describes how to use it. Let's take a look at helloworld of easyjweb and look at its original template:
Helloworldhas only one index.html page. The content is as follows:
<HTML xmlns = "http://www.w3.org/1999/xhtml">
"Title", "topic", "greeting", and "time" are used to indicate the prompt information for the above four languages, so that the "title" attribute must be displayed on the page, use $ Lang. get ("title. The index.html page behind the multilingual labels is as follows:
Next, create an applicationresources directory under the WEB-INF directory, and then create hello. properties and hello_zh_cn.properties in the directory to store English and Chinese information respectively, the content is as follows:
Hello. Properties
Greeting = the greeting from easyjweb
Time = Current Time
Title = the Hello world of easyjweb
Topic = the Hello world of easyjweb
Hello_zh_cn.properties
Greeting =/u6765/u81eaeasyjweb/u7684/u95ee/u5019
Time =/u73b0/u5728/u65f6/u95f4
Title = easyjweb/u7684hello world
Topic = easyjweb/u7248/u672c/u7684helloworld/u7a0b/u5e8f
Other codes do not need to be modified. Modify the browser's first language attribute to English and Chinese, and then open hello. EJF. You will see the result as shown in:
(The preferred language is the browsing effect of the Chinese text)
(Browsing effect when the preferred language is English)
From the running effect of the program, we can see that the four fixed chinese information on the previous page now supports internationalization. If you want to increase support for Korean and Japanese, you only need to add the hello_ko_kr.properties and hello_ja.properties files under the WEB-INF/applicationresources directory, and enter the attribute values such as "title.
Of course, through figure XX, we find that this program is not completely "internationalized". Because the MSG value from helloaction has been written to death, no matter who you meet, there is still a Chinese character in greeting: "Hello, this is the first program of easyjweb! ".
In easyjweb, it is very easy to use multi-language information in a program. You can directly call the get ("attribute name") method in the i18n tool class. Modify the code in helloaction and put the following:
Form. addresult ("MSG", "Hello, this is the first program of easyjweb! ");To:
Form. addresult ("MSG", i18n. Get ("message "));//I18n. Get ("message") indicates loading the message attribute from a multi-language file
Then we add the message attribute content in hello. properties, as follows:
Message = Hello, this is the first program of easyjweb!
Add the message attribute to hello_zh_cn.properties as follows:
Message =/u60a8/u597d/uff0c/u8fd9/u662feasyjweb/u7684/u7b2c/u4e00/u4e2a/u7a0b/u5e8f/uff01
Run the modified program and navigate to the English environment to get the result shown in XXX:
Added multi-country template support
In order to meet the English country's favorite page layout, we can find a directory under the WEB-INF/views/hellodirectory, then upload an index.html file in the directory, the file content is as follows:
When the client's preferred language is English, when accessing hello. EJF? When cmd = index, the file Hello/en/index.html is used as the view template output, as shown in:
When non-English users in the preferred language of other clients access the same URL, the "Hello/index.html" file is used as the view template output, as shown in.
The entire process is very simple. You do not need to modify any Java code or configuration file. You need to design and create pages for the page designer.