The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
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
类是区分区域设置的;它返回的数字的格式取决于Locale
。Thus 因此,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
对象:
When creating a 创建Locale
object, you usually specify a language code and a country code. A third parameter, the variant, is optional.Locale
对象时,通常指定语言代码和国家/地区代码。第三个参数,变体,是可选的。
This section shows you how to add a Unicode locale extension or a private use extension to a Locale.本节介绍如何将Unicode区域设置扩展或专用扩展添加到Locale。
Locale-sensitive classes support only certain 区域设置敏感类仅支持某些Locale
definitions. This section shows you how to determine which Locale
definitions are supported.Locale
定义。本节将向您展示如何确定支持哪些Locale
定义。
This section describes the internationalization support for language tags, language tags filtering, and language tags lookup.本节介绍对语言标记、语言标记筛选和语言标记查找的国际化支持。
On the Java platform you do not specify a global 在Java平台上,您不会在运行应用程序之前通过设置环境变量来指定全局Locale
by setting an environment variable before running the application. Locale
。Instead you either rely on the default Locale or assign a 相反,您要么依赖默认的区域设置,要么为每个Locale
to each locale-sensitive object.Locale
敏感的对象分配一个区域设置。
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(服务提供程序接口)还提供对更多区域设置的支持。