Struts2 internationalization (II)-dynamically loading international resource files using hyperlinks

Source: Internet
Author: User

Principle: The program determines the international resource file according to locale. ThereforeKey PointsKnows how the struts2 framework determines the local object!

Because struts2 uses the i18n Interceptor to process internationalization and registers it in the default interceptor, you can read the i18n interceptor.

The process of determining the locale object is as follows:

> Struts2 uses the i18n Interceptor to process internationalization and registers it in the default interceptor stack.

> Before the i18n interceptor executes the action method, it automatically finds a parameter named request_locale in the request.

If this parameter exists, the interceptor converts it to a locale object and sets it as the user's default locale (representing the country/language environment ).
Set it to the ww_trans_i18n_locale attribute of the session.

> If the request does not have a parameter named request_locale, The i18n interceptor obtains the value of ww_trans_i18n_locale from the session,
If this value is not blank, set this attribute value to the default locale of the browser.

> If the value of the ww_trans_i18n_locale attribute in the session is null, obtain the locale object from actioncontext.

The flowchart is shown in:

 

Specific implementation:You only need to attach the request_locale request parameter to the end of the hyper-connection. The value is the country code of the language.

<A href = "testi18n. Action? Request_locale = en_us "> English </a>
<A href = "testi18n. Action? Request_locale = zh_cn "> Chinese </a>

>Note:The hyperlink must be a struts2 request (executed by action), even if the i18n interceptor works!

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.