[Java Study Notes] Localization

Source: Internet
Author: User

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

First, we will introduce several terms:

  • I18n:Is internationalization, international, because the first letter "I" and the end letter "N" has 18 characters, so i18n for short. internationalization refers to the design measures taken to adapt applications to changes in different languages and regions without systematic changes.
  • L10n:It is localization. Because there are 10 letters between the first letter "L" and the last letter "N", l10n for short. localization refers to the process of adding local specialized components and translated text to enable application software to be used in a specific language environment or region.
  • Locale:In short, it is a sign of a special combination of languages and regions.

1. Localization of Text

Import java. util. resourcebundle;
Import java. util. locale;
Public class i18ndemo1 {
Static public void main (string Arg []) {
Locale LOC;
Resourcebundle bundle;
/* File:Demo1_en_us.properties*/
Loc = new locale ("en", "us ");
Bundle = resourcebundle. getbundle ("Demo1", Loc );
System. Out. println (bundle. getstring ("greeting "));
System. Out. println (bundle. getstring ("Question "));
System. Out. println (bundle. getstring ("farewell "));
System. Out. println ("--------------------------");
/* File:Demo1_en_us_tx.properties*/
Loc = new locale ("En "," us "," TX");
Bundle = resourcebundle. getbundle ("Demo1", Loc );
System. Out. println (bundle. getstring ("greeting "));
System. Out. println (bundle. getstring ("Question "));
System. Out. println (bundle. getstring ("farewell "));
}
}

The local configuration file is as follows:

Demo1_en_us.properties:

Greeting = hello.
Farewell = goodbye.
Question = Are you ready?

Demo1_en_us_tx.properties:

Greeting = howdy.
Farewell = S' long.
Question = is your gun loaded?

Naming rules for international resource files require that resource names be named in the following ways: <Resource Name >_< language code >_< country code>. Properties
The language code and country code are optional.

2. Digital Localization:

Import java. util. locale;
Import java. util. date;
Import java. Text. numberformat;
Import java. Text. dateformat;
Public class i18ndemo2 {
Static public void main (string Arg []) {
I18ndemo2 demo = new i18ndemo2 ();
Demo. showloc (New locale ("en", "us "));
System. Out. println ("-----------");
Demo. showloc (New locale ("FR", "FR "));
System. Out. println ("-----------");
Demo. showloc (New locale ("de", "de "));
}
Public void showloc (locale LOC ){
Numberformat nfmt;
Dateformat dfmt;
System. Out. println (LOC );
Nfmt = numberformat. getnumberinstance (LOC );
System. Out. println (nfmt.format (123456 ));
System. Out. println (nfmt.format (123456.78 ));
Nfmt = numberformat. getcurrencyinstance (LOC );
System. Out. println (nfmt.format (123456.78 ));
Nfmt = numberformat. getpercentinstance (LOC );
System. Out. println (nfmt. Format (. 78 ));
Dfmt = dateformat. getdateinstance (dateformat. Default, Loc );
System. Out. println (dfmt. Format (new date ()));
}
}

3. Check what localization is supported:

Import java. util. locale;
Import java. Text. numberformat;
Public class i18ndemo3 {
Static public void main (string Arg []) {
Locale loc [] = numberformat. getavailablelocales ();
For (INT I = 0; I <LOC. length; I ++)
System. Out. println (loc [I]);
}
}

Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/

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.