Java framework --- Struts2 localization/internationalization (i18n)

Source: Internet
Author: User

Java framework --- Struts2 localization/internationalization (i18n)
I18n is a planning and implementation product and service that enables them to easily adapt to specific local languages and cultures. This process is called localization. The process of internationalization is sometimes referred to as enabling translation or localization. I18n is short for internationalization, Because I and the two ends use n to start with, and there are 18 characters between I and the last n. Access Method: There are several methods to access information resources, including gettext, text tags, key attributes of UI tags, and International tags. Let's take a look at their simplicity: to display i18n text, use the call property tag gettext, or any other tag, for example, the UI tag is as follows: <s: property value = "getText ('some. key') "/> text tag to retrieve from the default resource package, that is, a message struts. properties <s: text name = "some. key "/> Any resource bundle on the i18n tag push value stack. Other labels in the i18n label range can display the message of this resource package: <s: i18n name = "some. package. bundle "> <s: text name =" some. key "/> </s: i18n> key attributes of most UI tags, which can be used to retrieve messages from a resource package: <s: textfield key =" some. key "name =" textfieldName "/> The following directory of the internationalized processing structure is implemented: the configuration file Struts. xml <? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE struts PUBLIC "-// Apache Software Foundation // DTD Struts Configuration 2.0 // EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name = "struts. devMode "value =" true "/> <! -- Scan files starting with global in the Resource Directory --> <constant name = "struts. custom. i18n. resources "value =" global "/> <package name =" helloworld "extends =" struts-default "namespace ="/"> <action name =" empinfo "class =" com. oumyye. action. employee "method =" execute "> <result name =" input ">/index. jsp </result> <result name = "success">/success. jsp </result> </action> <action name = "locale" class = "com. oumyye. action. locale "method =" execute"> <Result name = "success">/index. jsp </result> </action> </package> </struts> processing class: Employee. java package com. oumyye. action; import com. opensymphony. xwork2.ActionSupport; public class Employee extends ActionSupport {private String name; private int age; public String execute () {return SUCCESS;} public String getName () {return name ;} public void setName (String name) {this. name = name;} public int GetAge () {return age;} public void setAge (int age) {this. age = age ;}} processing class Locale. java package com. oumyye. action; import com. opensymphony. xwork2.ActionSupport; public class Locale extends ActionSupport {public String execute () {return SUCCESS ;}< % @ page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib prefix =" s "uri ="/struts-tags "%> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">

Related Article

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.