Internationalization Enhancements in Java SE 7 (original) (raw)
The Internationalization enhancements for Java SE 7 include the following:
- New Scripts and Characters from Unicode 6.0.0
- Extensible Support for ISO 4217 Currency Codes
- Category Locale Support
- Locale Class Supports BCP47 and UTR35
- New NumericShaper Methods
- Unicode 6.0 Support in Regular Expressions API
New Scripts and Characters from Unicode 6.0.0
Early versions of the Java SE 7 release added support for Unicode 5.1.0. The final version of the Java SE 7 release supports Unicode 6.0.0. Unicode 6.0.0 is a major version of the Unicode Standard and adds support for over 2000 additional characters, as well as support for properties and data files.
The Java Tutorial has a new section that discusses Unicode.
Extensible Support for ISO 4217 Currency Codes
Currencies are identified by their ISO 4217 codes. These codes maintained by an external agency and are released independent of the Java SE platform. As of Java SE 7, it is possible to accommodate new currencies without requiring a new release of the JDK.
To supersede the default currency at runtime, create a properties file named<JAVA_HOME>/lib/currency.properties
. This file contains the key/value pairs of the ISO 3166 country code, and the ISO 4217 currency data. The value part consists of three comma-separated ISO 4217 currency values: an alphabetic code, a numeric code, and a minor unit. Any lines beginning with the hash character, #
, are treated as comment lines. For example:
Sample currency property for Japan
JP=JPZ,999,0
The new API for this feature includes the following methods, all in the Currency
class:
- getAvailableCurrencies– Returns the set of available currencies.
- getNumericCode– Returns the ISO 4217 numeric code of this currency
- getDisplayName– Gets the name suitable for displaying this currency for the default locale.
- getDisplayName(Locale) – Gets the name suitable for displaying the specified locale.
Category Locale Support
The default locale can be independently set for two types of uses: the format setting is used for formatting resources, and the display setting is used in menus and dialogs. The new getDefault(Locale.Category) method takes aLocale.Category
parameter. Passing theFORMAT
enum to the method returns the default locale for formatting resources. Similarly, passing theDISPLAY
enum returns the default locale used by the UI. The setDefault(Locale.Category, Locale) method is used to set the locale for the specified category. The no-argumentgetDefault
method returns the DISPLAY
default value.
On Microsoft Windows, these default values are initialized according to the "Standard and Formats" and "Display Language" settings in the Windows control panel.
Locale Class Supports BCP47 and UTR35
The Locale
class has been updated to implement identifiers interchangeable with BCP 47 (IETF BCP 47, "Tags for Identifying Languages"), with support for the LDML (UTS#35, "Unicode Locale Data Markup Language") BCP 47-compatible extensions for locale data exchange.
The following nested classes have been added to theLocale
class in this release:
- Locale.Builder can be used to create a
Locale
instance and to configure that instance using setter methods.
The following methods have been added to the Locale
class:
- getExtensionKeys()
- getExtension(char)
- getUnicodeLocaleType(String
- getUnicodeLocaleKeys()
- getUnicodeLocaleAttributes()
- forLanguageTag(String)
- toLanguageTag()
- getScript()
- getDisplayScript()
- getDisplayScript(Locale)
The following constants have been added to theLOCALE
class:
For more information, see the Creating a Locale and BCP 47 Extensions lessons in the Java Tutorial.
New NumericShaper Methods
The NumericShaper
class is used to convert Latin-1 (European) digits to other Unicode decimal digits. For the Java SE 7 release, the NumericShaper.Rangeenum has been added to represent a Unicode range of a script having its own decimal digits. The following methods, using theNumericShaper.Range
enum have been added to the Java SE 7 release:
- getShaper(NumericShaper.Range) - returns a shaper for the provided Unicode range.
- getContextualShaper(Set<NumericShaper.Range>) - returns a contextual shaper for the provided Unicode range(s). The shaper assumes European as the starting context.
- getContextualShaper(Set<NumericShaper.Range> NumericShaper.Range) - returns a contextual shaper for the provided Unicode range(s). The shaper uses the
defaultContext
as the starting context. - shape(char[], int, int, NumericShaper.Range) - converts the digits in the text that occur between start and start + count, using the provided context.
For more information, see the Converting Latin Digits to Other Unicode Digits lesson in theJava Tutorial.
Unicode 6.0 Support in Regular Expressions API
The Regular Expressions pattern matching functionality has been expanded to support Unicode 6.0. You can match Unicode code points using either the \u
or the \x
escape sequence.
The Unicode Support page in the Java Tutorial has more information.