World Views

Locale Sensitive Services SPI

OK, the name of this new feature in Java SE 6 has become more complicated than we’d like it to be. What this “Locale Sensitive Services SPI” really means is that third parties can now provide implementations of most locale sensitive classes in the java.text and java.util packages for locales that aren’t yet supported by the Java runtime. “SPI” stands for “service provider interface,” a pattern that some developers are already familiar with from developing character converters, input methods, or other extensions. In this pattern, the Java platform provides interfaces or abstract classes that a developer can implement or subclass. The implementations or subclasses are then packaged with some descriptive information and installed into the Java runtime’s extension directory, and become available to applications through factory methods of the Java platform.

The locale-specific implementations that can be provided through the locale sensitive services SPI are:

Each of the classes mentioned above now has a corresponding abstract provider class in the java.util.spi or java.text.spi package. Concrete provider classes advertise the locales they support through their getAvailableLocales methods; these locales get added to the lists returned by the getAvailableLocales methods of the corresponding API classes. If an application requests an object for a locale that the JRE doesn’t support, a provider that supports the locale is asked to provide the necessary object.

An alternative to using an SPI might have been to simply document the format of the resource bundles used in implementing the java.text and java.util packages. This however would have required freezing the current format of the resource bundles, and we weren’t quite ready for that (in fact, we did redesign it for JDK 6). It would also have prevented the implementation of objects such as collators and break iterators that may require locale-specific code or data that doesn’t fit into the existing resource bundle format. Using an SPI gives developers complete freedom in the design of their implementations.

We also considered importing the complete data of the Unicode Consortium’s Common Locale Data Repository instead of providing an SPI. The CLDR covers about twice as many locales as Sun’s current JRE. However, importing the complete CLDR data would have added substantially to the JRE download size while still not helping users of locales that are not (yet) supported in the CLDR. Instead, we only used CLDR for a few additional locales. We think however that it would be worthwhile creating an extension that uses the SPI to support all locales that the CLDR provides but the JRE doesn’t. If you’re interested in helping with such a project, please let us know.

2005-06-27 (Montag) – Comments [2]
Kommentare:

How about adding Units to Locale? Metric vs English Units ( and maybe, Measures ) TonsPerFt2 TonsPerAcre MetricTonsPerHectare I have a product that I need to internationalize for LatinAmerica and Australia. International is not just about spelling and dates.

Gesendet von Paul Campbell am Juli 12, 2005 at 01:01 PM PDT #

Units are a pretty wide topic, and I’m not sure enough applications deal with them to warrant support in the Java SE platform itself. There is a separate JSR underway that attempts to define APIs for units (JSR 275); that’s probably a better approach. It might make sense to have a simple API that just states whether metric or English units are preferred in a locale; for that, you can vote for bug 4485686.

Gesendet von Norbert am Juli 13, 2005 at 03:17 PM PDT #

Senden Sie einen Kommentar:

Kommentare sind ausgeschaltet.
  © World Views. All rights reserved.