Java I18n 简明教程

Java Internationalization - Locale Class

Locale 类对象表示特定的地理/政治/文化区域。任何要求 Locale 执行其任务的操作称为区域设置敏感操作,它使用 Locale 来掌握与用户相关的信息。例如,显示数字是一种区域设置敏感操作。该数字应根据用户所在国家/地区或文化的习俗和惯例进行格式化。

A Locale class object represents a specific geographical/political/cultural region. Any operation requiring a Locale to perform its task is called locale-sensitive operation and uses the Locale to master information relative to the user. For example, displaying a number is a locale-sensitive operation. The number should be formatted as per the customs and conventions of the user’s native country, region, or culture.

Locale Contents

Locale 对象包含以下内容 −

A Locale object contains the following −

Language

ISO 639 alpha-2 或 alpha-3 语言代码,或最多 8 个字母的已注册语言子标签。如果 alpha-2 和 alpha-3 代码都存在,则必须使用 alpha-2 代码。语言字段不区分大小写,但语言环境始终标准化为小写。

ISO 639 alpha-2 or alpha-3 language code, or registered language subtags up to 8 alpha letters. alpha-2 code must be used if both alpha-2 and alpha-3 code are present. The language field is case insensitive, but Locale always canonicalizes to lower case.

Script

ISO 15924 alpha-4 书写系统代码。书写系统字段不区分大小写,但语言环境始终标准化为标题大小写。

ISO 15924 alpha-4 script code. The script field is case insensitive, but Locale always canonicalizes to title case.

Country (Region)

ISO 3166 alpha-2 国家代码或联合国 M.49 数字 3 地区代码。国家代码不区分大小写,但 Locale 始终标准化为大写。

ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code. The country field is case insensitive, but Locale always canonicalizes to upper case.

Variant

用于指示语言环境变体的任意值。如果存在两个或更多变体值,每个值都指示其自己的语义,那么这些值应该按重要性排序,最重要的优先,并用下划线('_')分隔。语言变体字段区分大小写。

Any arbitrary value used to indicate a variation of a Locale. Where there are two or more variant values each indicating its own semantics, these values should be ordered by importance, with most important first, separated by underscore('_'). The variant field is case sensitive.

Extensions

从单个字符键到字符串值的一个映射,指示语言识别之外的扩展。语言环境中的扩展实现 BCP 47 扩展子标签和私有使用子标签的语义和语法。这些扩展不区分大小写,但语言环境会将所有扩展键和值标准化为小写。

A map from single character keys to string values, indicating extensions apart from language identification. The extensions in Locale implement the semantics and syntax of BCP 47 extension subtags and private use subtags. The extensions are case insensitive, but Locale canonicalizes all extension keys and values to lower case.