Java Web Internationalization

Source: Internet
Author: User
Tags dateformat i18n locale

First, the locale class

locale locale = Locale.china; Locale locale = new locale ("zh", "CN"); System.out.println (Locale.getlanguage ()); System.out.println (Locale.getdisplaycountry ()); System.out.println (Locale.getdisplaylanguage ());

Second, DateFormat class

Date date = new Date (); SYSTEM.OUT.PRINTLN (date); Locale locale = new locale ("zh", "cn");D Ateformat DateFormat = dateformat.getdateinstance (dateformat.full, locale); System.out.println (Dateformat.format (date)); String dates = "2017-3-17";D ateformat df = new SimpleDateFormat ("Yyyy-mm-dd"); System.out.println (Df.parse (dates));

Third, NumberFormat class

Double d = 1.12d; Locale locale = locale.china;//formatted as currency numberformat NumberFormat = numberformat.getcurrencyinstance (locale);// Formatted as a digital NumberFormat numberFormat2 = numberformat.getnumberinstance (locale);//formatted as a percentage numberformat NUMBERFORMAT3 = Numberformat.getpercentinstance (locale); System.out.println (Numberformat.format (d)); System.out.println (Numberformat2.format (d)); System.out.println (Numberformat3.format (d));

Four, Messageformat class

String str = "{0},{1}"; String STRs = Messageformat.format (str, "UserName", "admin"); System.out.println (STRs);

Five, ResourceBundle class

ResourceBundle bundle = Resourcebundle.getbundle ("i18n", New Locale ("en", "US"); System.out.println (bundle.getstring ("UserName"));

VI. International Resource Documents

I18n.properties Username=username

I18n_zh_cn.properties username=\u7528\u6237\u540d

I18n_en_us.properties Username=username


Note: i18n is the base name, en is the language code, CN is the country code


Vii. FMT tags for JSP pages

<%@ taglib prefix= "FMT" uri= "http://java.sun.com/jsp/jstl/fmt"%> <%locale locale = locale.us;//locale locale = Locale.china;request.setattribute ("locale", locale); System.out.println (Request.getlocale ());//print out all the resources configured in the application International file Enumeration<locale> enumeration = Request.getlocales (); while (Enumeration.hasmoreelements ()) {Locale locale2 = enumeration.nextelement (); System.out.println (locale2);} %><fmt:setlocale value= "${requestscope.locale}"/>${requestscope.locale}<fmt:setbundle basename= "i18n "/><fmt:message key=" UserName "></fmt:message><fmt:formatnumber type=" currency "value=" 123 "> </fmt:formatNumber>


This article is from the "11137669" blog, please be sure to keep this source http://11147669.blog.51cto.com/11137669/1907741

Java Web Internationalization

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.