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

setlocale_create_locale 函数的 locale 参数可使用 Windows NLS API 支持的区域设置名称、语言、国家/地区代码和代码页设置。The locale argument to the setlocale and _create_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 :: "locale_name"locale :: "locale_name"
    | "language[_country-region][.code_page]]"    | "language[_country-region][.code_page]]"
    | ".code_page"    | ".code_page"
    | "C"    | "C"
    | ""    | ""
    | NULL    | NULL

首选区域设置名称格式,例如英语(美国)使用 en-US,或波斯尼亚语(西里尔文,波斯尼亚和黑塞哥维那)使用 bs-Cyrl-BAThe locale name form is preferred; for example, use en-US for English (United States) or bs-Cyrl-BA for Bosnian (Cyrillic, Bosnia and Herzegovina). Locale Names(区域设置名称)中介绍了这一系列区域设置名称。The set of locale names is described in Locale Names. 有关 Windows 操作系统版本支持的区域设置名称的列表,请参阅 的“区域性名称” National Language Support (NLS) API Reference(区域语言支持 (NLS) API 参考列。For a list of supported locale names by Windows operating system version, see the Culture Name column of the National Language Support (NLS) API 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 操作系统(按版本)中的语言和位置支持的其他信息,请参阅“[MS-LCID]:Windows 语言代码标识符 (LCID) 参考”中的附录 A:产品行为For additional information about language and location support in the Windows operating system by version, see Appendix A: Product Behavior in [MS-LCID]: Windows Language Code Identifier (LCID) Reference. 在 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.

使用语言字符串或语言字符串和国家/地区字符串创建区域设置时, language[_country_region[.code_page]] 格式将存储在类别的区域设置中。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/region string, is used to create the locale. Language Strings中介绍了一系列受支持的语言字符串, Country/Region Strings中则列出了受支持的国家/地区字符串。The set of supported language strings is described in Language Strings, and the list of supported country/region strings is listed in Country/Region Strings. 如果指定的语言与指定的国家/地区无关联,则将指定国家/地区的默认语言存储在区域设置中。If the specified language is not associated with the specified country/region, the default language for the specified country/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.

代码页是与区域设置关联的 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.

如果你仅使用代码页指定区域设置,则将使用系统默认语言和国家/地区。If you use only the code page to specify the locale, the system default language and country/region are used. 例如,如果指定 ".1254" (ANSI 土耳其语)作为系统上为英语(美国)配置的区域设置,则存储的区域设置是 English_United States.1254For example, if you specify ".1254" (ANSI Turkish) as the locale on a system 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 :: localeLC_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、_wsetlocale setlocale, _wsetlocale
_create_locale、_wcreate_locale _create_locale, _wcreate_locale
语言字符串 Language Strings
国家/地区字符串Country/Region Strings