UCRT 区域设置名称、语言和国家/地区字符串UCRT Locale names, Languages, and Country/Region strings

可使用 Windows NLS API 支持的区域设置名称、语言、国家/地区代码和代码页,设置 setlocale、_wsetlocale_create_locale_wcreate_locale 函数的 locale** 参数。The locale argument to the setlocale, _wsetlocale, _create_locale, and _wcreate_locale functions can be set by using the locale names, languages, country/region codes, and code pages that are supported by the Windows NLS API. locale 参数采取以下格式:The locale argument takes the following form:

区域设置: "locale-name"locale :: "locale-name"
    |"language [ _ 国家/地区 [ 代码页]] "    | "language[_country-region[.code-page]]"
    |".代码页"    | ".code-page"
    | "C"    | "C"
    | ""    | ""
    | NULL    | NULL

locale-name** 是简易格式的 IETF 标准化字符串;例如,en-US 表示英语(美国),或 bs-Cyrl-BA 表示波斯尼亚语(西里尔文,波斯尼亚和黑塞哥维那)。The locale-name form is a short, IETF-standardized string; for example, en-US for English (United States) or bs-Cyrl-BA for Bosnian (Cyrillic, Bosnia and Herzegovina). 首选这些格式。These forms are preferred. 有关 Windows 操作系统版本支持的区域设置名称的列表,请参阅附录 a:产品行为in MS-LCID]: Windows 语言代码标识符(LCID)参考中的表的语言标记列 [ 。For a list of supported locale names by Windows operating system version, see the Language tag column of the table in Appendix A: Product Behavior in [MS-LCID]: Windows Language Code Identifier (LCID) Reference. 该资源列出了支持的语言、脚本和区域设置名称的地区部分。This resource lists the supported language, script, and region parts of the locale names. 有关采用非默认排序顺序的受支持的区域设置名称的信息,请参阅 **** 中的“区域性名称” Sort Order Identifiers(排序顺序标识符)列。For information about the supported locale names that have non-default sort orders, see the Locale name column in Sort Order Identifiers. 在 Windows 10 或更高版本下,允许使用对应于有效的 BCP-47语言标记的区域设置名称。Under Windows 10 or later, locale names that correspond to valid BCP-47 language tags are allowed. 例如,jp-US 是一个有效的 BCP-47 标记,但实际上只有 US 对于区域设置功能有效。For example, jp-US is a valid BCP-47 tag, but it is effectively only US for locale functionality.

语言" [ _ 国家/地区" [ 代码页]]当使用语言字符串或语言字符串和国家/地区字符串创建区域设置时,窗体存储在类别的区域设置中。The language[_country-region[.code-page]] form is stored in the locale setting for a category when a language string, or language string and country or region string, is used to create the locale. 语言字符串介绍了一系列受支持的语言字符串,国家/地区字符串列出了受支持的国家和地区字符串。The set of supported language strings is described in Language Strings, and the list of supported country and region strings is listed in Country/Region Strings. 如果指定语言没有与指定国家/地区关联,指定国家/地区的默认语言存储在区域设置中。If the specified language is not associated with the specified country or region, the default language for the specified country or region is stored in the locale setting. 我们不建议将区域设置字符串的该格式嵌入到代码中或序列化到存储中,因为操作系统的更新更改这些字符串的可能性要高于区域设置名称格式。We do not recommend this form for locale strings embedded in code or serialized to storage, because these strings are more likely to be changed by an operating system update than the locale name form.

code-page** 是与区域设置关联的 ANSI/OEM 代码页。The code-page is the ANSI/OEM code page that's associated with the locale. 通过语言或通过语言和国家/地区单独指定区域设置时,代码页已为你确定。The code page is determined for you when you specify a locale by language or by language and country/region alone. 特殊值 .ACP 将指定国家/地区的 ANSI 代码页。The special value .ACP specifies the ANSI code page for the country/region. 特殊值 .OCP 将指定国家/地区的 OEM 代码页。The special value .OCP specifies the OEM code page for the country/region. 例如,如果指定 "Greek_Greece.ACP" 作为区域设置,区域设置则存储为 Greek_Greece.1253 (希腊语的 ANSI 代码页);如果指定 "Greek_Greece.OCP" 作为区域设置,它则存储为 Greek_Greece.737 (希腊语的 OEM 代码页)。For example, if you specify "Greek_Greece.ACP" as the locale, the locale is stored as Greek_Greece.1253 (the ANSI code page for Greek), and if you specify "Greek_Greece.OCP" as the locale, it is stored as Greek_Greece.737 (the OEM code page for Greek). 有关代码页的详细信息,请参见 Code PagesFor more information about code pages, see Code Pages. 有关 Windows 支持的代码页列表,请参阅 Code Page Identifiers(代码页标识符)For a list of supported code pages on Windows, see Code Page Identifiers.

如果你仅使用代码页指定区域设置,则将使用 GetUserDefaultLocaleName 所报告的用户的默认语言和国家/地区。If you use only the code page to specify the locale, the user's default language and country/region as reported by GetUserDefaultLocaleName are used. 例如,如果指定 ".1254"(ANSI 土耳其语)作为系统上为英语(美国)配置的用户区域设置,则存储的区域设置是 English_United States.1254For example, if you specify ".1254" (ANSI Turkish) as the locale for a user that's configured for English (United States), the locale that's stored is English_United States.1254. 我们不建议使用该格式,因为它可能导致不一致的行为。We do not recommend this form, because it could lead to inconsistent behavior.

Clocale 参数值 为 C 转换指定最小的符合 ANSI 标准的环境。A locale argument value of C specifies the minimal ANSI conforming environment for C translation. C区域设置假定每个 char 数据类型都为1个字节,并且其值始终小于256。The C locale assumes that every char data type is 1 byte and its value is always less than 256. 如果 locale 指向一个空字符串,则区域设置是实现定义的本机环境。If locale points to an empty string, the locale is the implementation-defined native environment.

使用 setlocale 类别,可以为 _wsetlocaleLC_ALL 函数同时指定所有区域设置类别。You can specify all of the locale categories at the same time for the setlocale and _wsetlocale functions by using the LC_ALL category. 这些类别可以全部设置为同一区域设置,你也可以使用具有该格式的区域设置参数分别设置每个类别:The categories can all be set to the same locale, or you can set each category individually by using a locale argument that has this form:

LC-ALL-specifier** :: locale**LC-ALL-specifier :: locale
    | [LC_COLLATE=**** locale__][;LC_CTYPE=**** locale__][;LC_MONETARY=**** locale__][;LC_NUMERIC=**** locale__][;LC_TIME=**** locale__]    | [LC_COLLATE=locale][;LC_CTYPE=locale][;LC_MONETARY=locale][;LC_NUMERIC=locale][;LC_TIME=locale]

你可以指定多个类别类型,由分号分隔。You can specify multiple category types, separated by semicolons. 未指定的类别类型使用当前的区域设置。Category types that are not specified use the current locale setting. 例如,该代码片段将所有类别的当前区域设置设为 de-DE,然后将类别 LC_MONETARY 设为 en-GB,将 LC_TIME 设为 es-ESFor example, this code snippet sets the current locale for all categories to de-DE, and then sets the categories LC_MONETARY to en-GB and LC_TIME to es-ES:

_wsetlocale(LC_ALL, L"de-DE");
_wsetlocale(LC_ALL, L"LC_MONETARY=en-GB;LC_TIME=es-ES");

另请参阅See also

C 运行时库参考C Run-Time Library Reference
_get_current_locale_get_current_locale
setlocale、_wsetlocalesetlocale, _wsetlocale
_create_locale、_wcreate_locale_create_locale, _wcreate_locale
语言字符串Language Strings
国家/地区字符串Country/Region Strings