JDK internationalization Overview

Source: Internet
Author: User
Tags collator dateformat intl month name time in milliseconds framemaker
JDK internationalization Overview

Introduction

Modification date: October 5

The global internet requires globalized software-that is, software can be developed independently of the user's country or language, and then localized in multiple countries and regions. JDK (Java Development Kit) provides a large number of global applications for development.ProgramAPI (application interface ). These international APIs are encoded Based on Unicode 2.0 characters and can make texts, numbers, dates, currencies, and user-defined objects suitable for any country's habits.

This article summarizes the functions of international APIs and JDK software. For more information about coding examples and detailed instructions, see the Java tutorial. For more information about APIs, see Java API specifications.

For more information, see the JDK International homepage.

Locale

In Java, locale is only the identifier of a combination of languages and regions. It is not a set of locale-related attributes. Each locale-sensitive class stores its own locale-related information. In this way, there is no difference in how users and System Objects save their locale-related resources. They all use standard localization mechanisms.

Java programNoSpecify a global locale. For all locale-sensitive operations, you can specify locale as its parameter. This greatly simplifies multilingual programs. Although global locale is not forcibly specified, the default locale can still be used for programs that do not want to explicitly manage locale. By default, locale can also be selected once to affect all representation.

Java locale acts as a request for a behavior from another object. For example, the locale in the French region where the Calendar Object is passed in requires that the calendar be correctly operated to conform to the habits of Quebec. The object should accept the requirements of locale and make the correct response. If the object has not been localized for a locale, it will try to find a localized locale that matches "closest" to it. Therefore, if the Calendar Object has not yet been localized for the French-speaking Canada, but there is usually a localized version of the French language, it will be localized in the French language.

Locale class

The Locale object indicates a specific geographic, political, or cultural region. The operation that requires locale to execute its task is called a locale-sensitive operation. This operation uses the locale object to provide users with appropriate information. For example, displaying numbers is an operation that is sensitive to locale-the numbers should be formatted according to the user's country, region, or cultural habits and customs.

Objects represent a specific geographic, political, or cultural area. The operation that requires locale to execute its task is called a locale-sensitive operation. This operation uses the locale object to provide users with appropriate information. For example, displaying numbers is an operation that is sensitive to locale-the numbers should be formatted according to the user's country, region, or cultural habits and customs.

Supported locale

On the Java platform, there is no need to have a single set of supported locale, because each class has its own localization. Despite this, there is still a set of localization supported by the JDK software class. Other implementations of the Java platform support different locale. The Locale supported by JDK is summarized in the locale supported by the web page. Later JDK versions include other locale.

Localized Resources

All locale-sensitive classes must be accessible.

Resources customized by locale. During the localization process, it helps to group these resources by locale,

And separated from the parts irrelevant to locale in the program.

Resourcebundle class

Class resourcebundle is an abstract basic class that represents a resource container. The programmer creates a subclass of resourcebundle, which contains resources of a specific locale. You can add new resources to resourcebundle instances, or add new resourcebundle instances to the system without affectingCode. Packaging resources as classes allows developers to use the class loading mechanism of Java to find resources.

The resource package contains locale-related objects. When the program needs resources related to locale (such as string objects), the program can load it from the resource package corresponding to locale of the current user. This method allows programmers to write code to a large extent to get rid of the user's locale restrictions, while most (if not all) of the user's locale and resource package information related to locale is isolated.

Therefore, the code written by Java programmers can:

    • Easy localization or translation into different languages

    • Process multiple locale at a time

    • Easy to modify to support more locale

Listresourcebundle class

Listresourcebundle is an abstract subclass of resourcebundle. It manages resources of a locale in a convenient and easy-to-use list.

Is an abstract subclass of resourcebundle. It manages a locale resource in a convenient and easy-to-use list.

Propertyresourcebundle class

Propertyresourcebundle is a specific subclass of resourcebundle. It uses a static string set in the attribute file to manage resources of a locale.

Is a specific subclass of resourcebundle. It uses a static string set in the property file to manage resources of a locale.

Calendar and Time Zone support

JDK 1.0 introduces the java. util. Date class to indicate the date and time. The Java. util. Date class allows you to interpret a date as an equivalent of year, month, day, hour, minute, and second, and format and parse the date string. However, APIs of these functions do not support internationalization. JDK 1.1 only retains the "representation" part of the class.

In JDK 1.1, the date class should only be used as the wrapper of the date or time. This means that the date object represents a specific time point of time in milliseconds. However, programmers should use the calendar class to convert between the date and time fields, and use the dateformat class to format and parse the date string. In JDK 1.0, the corresponding method of the date class has been discarded.

Calendar class

Calendar is an abstract basic class. It can be converted between a certain point in time (represented in milliseconds since 00:00:00 GMT on January 1, January 1, 1970) and an integer set that represents years, months, and weeks. Gregoriancalendar is a subclass of calendar. It performs this conversion according to the rules of the Rome calendar.

Calendar and its subclass can be used to process different time values. It can be executed on the domain of the Calendar Object.AlgorithmAnd then determine the date. The Calendar Object can generate all the time domain values required for date-time formatting in a language or calendar style.

Timezone class

The abstract class timezone encapsulates the time zone offset of UTC (World Standard Time) and the possible offset of the daylight saving time. Simpletimezone is a concrete subclass, which encapsulates some simple rules about the Daylight Time System. These rules do not consider the historical changes that affect the daylight saving time. The calendar class and its subclass use the timezone and simpletimezone classes to convert between local time and UTC. UTC is the internal representation of the date object. Most programs do not need to directly process timezone objects.

Format

Many cultural habits require formatting and output data. Numbers, dates, times, and messages may need to be formatted before they are displayed. The Java platform provides a series of flexible formatting classes that can process both standard locale formats and custom formats by programmers. These formatting classes can also parse formatted strings into their objects.

Format class

The format class is an abstract basic class that is used to format information that is sensitive to locale, such as date, time, message, and number. It provides three main subclasses: dateformat, numberformat, and messageformat. These three subclasses also have their own subclasses.

Dateformat class

The date and time are stored independently of locale internally, but must be formatted for locale-sensitive display. For example, the same date should be formatted:

    • November 3, 1997 (English)

    • 3 novembre 1997 (French)

The class dateformat is an abstract basic class that formats and parses the date and time values in a way independent of locale. It has many static factory methods to obtain the standard time format for a given locale.

The dateformat object uses the calendar and timezone objects to explain the time value. By default, the dateformat object for a given locale uses the corresponding Calendar Object of the locale and the default timezone object of the system. Programmers can overwrite these options if they want.

Simpledateformat class

Simpledateformat is a type that formats and parses the date and time in a locale-sensitive manner. It allows formatting (milliseconds to text), parsing (text to milliseconds), and standardization.

Dateformatsymbols class

The dateformatsymbols class is used to encapsulate localized date-time format data, such as month name, week name, time in one day, and time zone data. Both the dateformat and simpledateformat classes use the dateformatsymbols class to encapsulate the information.

Programmers generally do not directly use dateformatsymbols. They use the factory method of the dateformat class for formatting.

Numberformat class

Numberformat is an abstract basic class used to format and parse digital data. It has many static factory methods to obtain different locale-related numeric formats.

Numberformat helps programmers format and parse arbitrary locale numbers. Code using this class can be completely independent of the decimal point, sub-digit, special decimal number, or even has nothing to do with whether the digit format is decimal. The application can also display numbers in standard decimal digits, currencies, or percentages:

    • 1234.5 (decimal number)

    • $1,234.50 (US currency)

    • Fr1.234, 5 (French currency)

    • 123450% (percentage)

Decimalformat class

Numbers are stored internally in a way independent of locale, but must be formatted for locale-sensitive display. For example, when "#, ###. 00" is used, the same number can be formatted:

    • 1.234, 56 (German)

    • 1,234.56 (English)

The decimalformat class is a subclass of the numberformat class. It can be used to format decimal numbers. Programmers generally do not directly instantiate this class, but use the factory method it provides.

The decimalformat class specifies how to format numbers based on the mode string. Mode specifies attributes, such as the precision of numbers, whether to display leading zeros, and what currency symbols are used. If the program needs to create a custom format, you can change the mode string.

Decimalformatsymbols class

Class decimalformatsymbols indicates the set of symbols used by decimalformat to format numbers (such as decimal separators and group delimiters ). Decimalformat creates a decimalformatsymbols instance for itself from its locale data. Programmers who need to change these symbols can obtain the decimalformatsymbols object from the decimalformat object and modify it.

Choiceformat class

Choiceformat is a subclass of the numberformat class. The choiceformat class allows programmers to apply formats to a series of numbers. It is usually used to process more than two numbers in the messageformat object. For more information, see the "messageformat class" section below.

Messageformat class

A program often needs to construct messages based on the sequence of strings, numbers, and other data. For example, the message text that shows the number of files in a disk drive is different:

    • Disk C contains 100 files.

    • Disk D contains 1 file.

    • Disk F contains 0 files.

If a message constructed in string or numeric order has been hard-coded, it cannot be translated into other languages. For example, note the position of parameters 3 and G in the following translations:

    • The disk G contains 3 files)

    • Il y a 3 fichiers sur le Disque G. (French)

Messageformat provides a method to generate continuous messages in a language-independent manner. The messageformat object accepts a group of objects, formats them, and inserts formatted characters into the corresponding position in the mode.

Parseposition class

The format class and its subclass use the parseposition class to track the current position during parsing. The parseobject () method in the format class must take the parseposition object as the parameter.

Fieldposition class

Format and its subclass use the fieldposition class to identify the fields in the formatted output. There is a version of the format () method in the format class that uses the fieldposition object as the parameter.

String operations sensitive to locale

The program often needs to operate on strings. Common Operations on strings include search and sorting. Some tasks (such as sorting strings or finding different boundaries in text) are difficult to complete correctly, and it is more difficult to consider multiple languages. JDK provides classes that can process many common string operations in a locale-sensitive manner.

Collator class

The collator class performs sorting on strings sensitive to locale. Programmers use this class to construct natural language text search and alphabetic sorting routines. Collator is an abstract basic class. Its sub-classes implement specific sorting principles. A subclass of rulebasedcollator currently provided by JDK is applicable to multiple languages. You can create other child classes to handle more specific requirements.

Class to sort strings sensitive to locale. Programmers use this class to construct natural language text search and alphabetic sorting routines. Collator is an abstract basic class. Its sub-classes implement specific sorting principles. A subclass of rulebasedcollator currently provided by JDK is applicable to multiple languages. You can create other child classes to handle more specific requirements.

Rulebasedcollator class

The rulebasedcollator class is a specific subclass of the collator class. It provides a simple, data-driven table sorting class. Programmers can use rulebasedcollator to create custom table-based sorting classes. For example, a programmer can construct a sorting class that ignores (or considers) uppercase letters, accents, and Unicode Character combinations.

A class is a specific subclass of the collator class. It provides a simple data-driven table sorting class. Programmers can use rulebasedcollator to create custom table-based sorting classes. For example, a programmer can construct a sorting class that ignores (or considers) uppercase letters, accents, and Unicode Character combinations.

Collationelementiterator class

The collationelementiterator class can be used as an iterator to move between every character of an internationalized string. The programmer uses the iterator to return the priority of the characters that have been located. The priority of characters or keywords defines how to sort characters in a given collator object. The compare () method of the rulebasedcollator class uses the collationelementiterator class.

Class can be used as an iterator to move between every character of an internationalized string. The programmer uses the iterator to return the priority of the characters that have been located. The priority of characters or keywords defines how to sort characters in a given collator object. The compare () method of the rulebasedcollator class uses the collationelementiterator class.

Collationkey class

The collationkey object represents a string that follows the rules of a specific collator object. Comparing Two collationkey objects returns the relative sequence of the strings they represent. Comparing strings with collationkey objects is usually faster than using collator. Compare. Therefore, when the string must be compared multiple times (such as sorting a column of strings), The collationkey object is more effective.

Object indicates a string that follows the rules of a specific collator object. Comparing Two collationkey objects returns the relative sequence of the strings they represent. Comparing strings with collationkey objects is usually faster than using collator. Compare. Therefore, when the string must be compared multiple times (such as sorting a column of strings), The collationkey object is more effective.

Breakiterator class

The breakiterator class indirectly finds the location of the following types of boundaries in text strings:

Class indirect method to find the location of the following types of boundary in a text string:

    • Possible line breaks

    • Sentence

    • Word

    • Character

In various languages, the habit of ending rows, sentences, words, and characters is different. Because the breakiterator class is sensitive to locale, the program can use it to perform text operations. For example, consider a word processing program that can highlight characters, cut words, move the cursor to the next sentence, or fold words at the end of a row. This type of word handler uses a separator iterator to determine the logical boundaries in the text so that it can perform text operations in a locale-sensitive manner.

Stringcharacteriterator class

The stringcharacteriterator class can be moved in Unicode strings in two directions. This class uses the cursor to move within a piece of text and can return each character or its index value. The stringcharacteriterator class implements the character iterator function of the characteriterator interface.

Class can be moved in Unicode strings in two directions. This class uses the cursor to move within a piece of text and can return each character or its index value. The stringcharacteriterator class implements the character iterator function of the characteriterator interface.

Characteriterator Interface

The characteriterator interface defines the protocol for Bidirectional movement of Unicode characters. This interface should be implemented if some classes are to be moved within a Text Segment and each UNICODE character or its index value is returned. The characteriterator used for searching is useful when performing character search.

The interface defines the protocol for Bidirectional movement in Unicode characters. This interface should be implemented if some classes are to be moved within a Text Segment and each UNICODE character or its index value is returned. The characteriterator used for searching is useful when performing character search.

Character Set Conversion

The Java platform uses Unicode as its local character encoding, but many Java programs still need to process text data that exists in other encoding methods. Therefore, Java provides a set of classes that can be converted back and forth between many standard character encodings and Unicode. Java programs that need to process non-Unicode text data usually convert the data to Unicode, process the data in Unicode mode, and then convert the result back to external character encoding. The inputstreamreader and outputstreamwriter classes provide methods for conversion between other character encoding and Unicode.

Supported Encoding

The inputstreamreader, outputstreamwriter, and string classes can be converted between the following encoding listed in Unicode and Webpage-supported encoding.

AWT attributes

To better internationalize the program GUI, JDK provides the following two attributes for the component class: Name and locale.

Name attribute

The name attribute is a string object, which is a non-localized identifier of the component object. The new constructor of the component class and its subclass allows you to set the name attribute. If you do not use these constructors, the default name is assigned to the component object. You can use the component. getname () method to check the name attribute of the component object.

The name attribute is particularly useful when writing an action processing routine, and the reference to the target cannot be known in advance in this class of routine. This action handler is usually generated by the GUI constructor. Previously, these routines tried to identify the target component by viewing its tag string. After the tag string is localized, this method fails. Like JDK 1.1, programmers should use the component. getname () method instead.

Locale attributes

The component class now contains the locale attribute. This attribute is accessed by methods getlocale () and setlocale () methods. If the locale of the component object is not explicitly set, the default value is locale of the parent class of the component object. If there is no component with a clear locale in the hierarchy, the default value is locale. getdefault.

The Locale attribute of component allows the GUI (or part of the GUI) to retain its own default locale. This is useful. For example, the rest of the browser uses American locale, while the applet can still use Japanese locale.

Stream I/O

In the java. Io package, JDK provides functions to improve character Date Processing: new reader and writer classes, and enhanced functions of the printstream class.

Reader and writer

The set of reader and writer classes can perform I/O operations on the volume stream. These sets combine the inputstream and outputstream classes in parallel, but operate on the bytes stream instead of the byte stream. The ghost stream makes it easier to write programs that do not depend on specific character encoding, so it is easier to internationalize. The reader and writer classes can also be converted between Unicode and other character encodings. For more information about reader and writer class levels, see the volume stream document.

And class set can execute I/O operations on the worker stream. These sets combine the inputstream and outputstream classes in parallel, but operate on the bytes stream instead of the byte stream. The ghost stream makes it easier to write programs that do not depend on specific character encoding, so it is easier to internationalize. The reader and writer classes can also be converted between Unicode and other character encodings. For more information about reader and writer class levels, see.

Printstream class

Printstream has been enhanced to use the system default character encoding and line terminator to generate output. This change allows methods such as system. Out. println () to perform more reasonable operations on non-ASCII data.

Enhanced to use the system default character encoding and line terminator to generate output. This change allows methods such as system. Out. println () to perform more reasonable operations on non-ASCII data.

Character Classification

The Java platform stores character data in Unicode (an international character set standard) mode. The Unicode standard uses 16-bit encoding to support all major character sets worldwide, including common technical symbols. Most Java code is written in ASCII (7-bit standard) or ISO-Latin-1 (8-bit standard), but is converted to Unicode before processing. Therefore, the Java character set is always represented by Unicode.

JDK 1.0 introduces the character class as the wrapper object of the basic character type. The character class also contains static methods such as islowercase () and isdigit () to determine character attributes. This method has been extended in JDK 1.1 to allow access to all character attributes defined in Unicode 2.0.

Input Method

Because the Chinese, Japanese, and Korean character sets are large, keyboard ing is not feasible for them. To input text in an application, you often use a front-end tool called the input method. The input method allows you to pre-create Asian character sets and then send them to applications.

The term "Input Method" does not refer to JavaProgramming Language. The host platform (such as Solaris or Windows) supports the input method. The current JDK version (1.2.0) does not contain the input method engine.

In versions compatible with JDK 1.1, you can use the input method to input text in textfield and textarea AWT components.

Supported on-the-spot input in swing

JDK 1.2 supports on-the-spot (Inline) editing through the Input Method Framework. On-the-spot editing is a function of the input method, which allows users to directly input text to the text field. When you use on-the-spot to edit the input text, the input method inserts the text directly into the text component. Application developers do not have to coordinate the actions between input methods and text components. When the text component is enabled for on-the-spot editing, the coordination work required by JDK software processing is required. However, when all text must be submitted (for example, when saving or printing a document), developers should call inputcontext. endcompostion. The inputcontext class is part of the Input Method Framework.

Input Method Framework

The Input Method Framework is a set of Apis provided by JDK 1.2. The input method framework enables the text editing component to interact with the input method. Programmers who develop text editing components should use the Input Method Framework. Application developers generally do not use the Input Method Framework. However, when all text must be submitted (for example, when saving or printing a document), application developers should call inputcontext. endcompostion.

The webpage of the Input Method Framework contains links to specifications and API documents.

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.