Documentation

The Java™ Tutorials
Hide TOC
Setting the Locale设置区域设置
Trail: Internationalization

Lesson: Setting the Locale课:设置区域设置

An internationalized program can display information differently throughout the world. 国际化的程序可以在全世界以不同的方式显示信息。For example, the program will display different messages in Paris, Tokyo, and New York. 例如,该程序将在巴黎、东京和纽约显示不同的消息。If the localization process has been fine-tuned, the program will display different messages in New York and London to account for the differences between American and British English. 如果本地化过程得到了微调,该节目将在纽约和伦敦显示不同的信息,以解释美式英语和英式英语之间的差异。How does an internationalized program identify the appropriate language and region of its end users? 国际化项目如何确定其最终用户的适当语言和地区?Easy. It references a Locale object.简单易用!它引用Locale对象。

A Locale object is an identifier for a particular combination of language and region. If a class varies its behavior according to Locale, it is said to be locale-sensitive. Locale对象是语言和区域的特定组合的标识符。如果一个类根据Locale改变其行为,则称其为区域设置敏感类For example, the NumberFormat class is locale-sensitive; the format of the number it returns depends on the Locale. 例如,NumberFormat类是区分区域设置的;它返回的数字的格式取决于LocaleThus NumberFormat may return a number as 902 300 (France), or 902.300 (Germany), or 902,300 (United States). Locale objects are only identifiers. 因此,NumberFormat可以返回902 300(法国)、902.300(德国)或902300(美国)的数字。Locale对象只是标识符。The real work, such as formatting and detecting word boundaries, is performed by the methods of the locale-sensitive classes.真正的工作,例如格式化和检测单词边界,是由区域设置敏感类的方法执行的。

The following sections explain how to work with Locale objects:以下部分介绍如何使用Locale对象:

Creating a Locale创建区域设置

When creating a Locale object, you usually specify a language code and a country code. A third parameter, the variant, is optional.创建Locale对象时,通常指定语言代码和国家/地区代码。第三个参数,变体,是可选的。

BCP 47 ExtensionsBCP 47扩展

This section shows you how to add a Unicode locale extension or a private use extension to a Locale.本节介绍如何将Unicode区域设置扩展或专用扩展添加到Locale

Identifying Available Locales识别可用的区域设置

Locale-sensitive classes support only certain Locale definitions. This section shows you how to determine which Locale definitions are supported.区域设置敏感类仅支持某些Locale定义。本节将向您展示如何确定支持哪些Locale定义。

Language Tag Filtering and Lookup语言标记筛选和查找

This section describes the internationalization support for language tags, language tags filtering, and language tags lookup.本节介绍对语言标记、语言标记筛选和语言标记查找的国际化支持。

The Scope of a Locale区域设置的范围

On the Java platform you do not specify a global Locale by setting an environment variable before running the application. 在Java平台上,您不会在运行应用程序之前通过设置环境变量来指定全局LocaleInstead you either rely on the default Locale or assign a Locale to each locale-sensitive object.相反,您要么依赖默认的区域设置,要么为每个Locale敏感的对象分配一个区域设置。

Locale-Sensitive Services SPI区域设置敏感服务SPI

This section explains how to enable plug-in of locale-dependent data and services. These SPIs (Service Provider Interface) provides support of more locales in addition to the currently available locales.本节介绍如何启用依赖于区域设置的数据和服务的插件。除了当前可用的区域设置之外,这些SPI(服务提供程序接口)还提供对更多区域设置的支持。


Previous page: Previous Lesson
Next page: Creating a Locale