Java multi-national language problem solving solution

Source: Internet
Author: User

With the development of economic globalization, the emergence of a large number of multinational companies, and the advent of the Java language and the rapid development of network communications technology, so that enterprises buy only a set of web-based enterprise application software (such as: OA system, ERP system, CRM, etc.), through the network can meet the whole group to use the software to become possible. Not only reduces the software cost, but also shortens the information delay and improves the operation efficiency of the enterprise. But because the application system is for many countries, many languages, so in the design of software will have to solve the problem of internationalization (internationalization), the internationalization of the program should support multiple languages, different formats of date, time, currency and other values, as well as the style of the operating interface, Interface customization and other issues. This paper focuses on the solution of multi-national language:

The Java language is an object-oriented language, so it is possible to generate an internationalized software package that can be judged automatically by the system based on regional and language-setting attributes.

There are two main types of solutions:

The first is to use Java itself to provide solutions for internationalization problems in the package of ResourceBundle and its subclasses, processing in the Java class or the property file defined in the parameters, the second is to customize a class for access, the corresponding parameters in the database or properties file.

First, the use of Java class package:

1, according to the system default language settings to read the parameter values of the class resource:

Package i18n.article
Import java.io.*;
import java.util.Enumeration;
Import java.util.Hashtable ;
Import Java.util.Locale;
Import Java.util.PropertyResourceBundle;
Import Java.util.ResourceBundle;
/**
* <p>title: Background implementation class </P> in a multinational language;
* <p>description: The corresponding language </p> according to the property file and locale and language settings;
* <p>copyright:copyright (c) 2003</p>
* <p>company:timer corporation</p>
* @author: 宋兆辉 br> * @version 1.0
*/
public class Resource {
private static final String Head_file = "ATTR";//prefix of property filename
private static final String last_file= ". Properties"; The suffix of the property file name
private static final String file_path= "c://";//define the directory where the property file is stored
Public Resource () {
}
/* Below is based on the incoming genus The "key" in the sex file, and gets the "value" */
Public synchronized String Srcstr (string disstr) {
String ret = "", which corresponds to the locale and language setting;
try {
Locale Locale = Locale.getdefault ();//Get the locale and language default settings for the system
System.out.println ("");
String baseName = new STRIngbuffer ()
. Append (Head_file). Append ("_"). Append (Locale.tostring ())
. Append (Last_file). toString ();// Based on the local property, prefix and suffix generation file name
String filename = new StringBuffer (file_path). Append (BaseName)
. toString ();//Get the full path of the file
InputStream is = new FileInputStream (fileName);//generate file Input stream
propertyResourceBundle PR = new propertyResourceBundle (IS); Constructs an instance of propertyResourceBundle from an input stream
ret = pr.getstring (DISSTR);
if (Locale.equals (Locale.china)) {
ret = new String (Ret.getbytes ("iso-8859-1"), "GB2312");
}//If you want to display Chinese, convert the inner code
Is.close ();
return ret;
}
catch (Exception e) {
E.printstacktrace ();
return disstr;
}
}
}

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.