# node: getLocaleProperties URL: https://generaltranslation.com/zh/docs/node/api/get-locale-properties.mdx --- title: getLocaleProperties description: getLocaleProperties 函数的 API 参考文档 --- ## 概述 `getLocaleProperties` 函数返回给定区域设置的元数据,包括其名称、本地名称、语言、地区和书写系统信息。 ```js import { getLocaleProperties } from 'gt-node'; const props = getLocaleProperties('en-US'); console.log(props.name); // '美式英语' ``` ## 参考文档 ### 参数 | 参数 | 类型 | 描述 | | -------- | -------- | ----------------------------------------------------- | | `locale` | `string` | BCP 47 区域设置代码 (例如 `'en-US'`、`'ja'`) 。如果未提供,则使用当前区域设置。 | ### 返回值 一个 `LocaleProperties` 对象,包含以下字段: | 字段 | 类型 | 说明 | | -------------------------- | -------- | ------------------------------------------- | | `code` | `string` | 区域设置代码 (例如 `'en-US'`) 。 | | `name` | `string` | 区域设置的英文名称 (例如 `'American English'`) 。 | | `nativeName` | `string` | 该区域设置在其自身语言中的名称 (例如 `'American English'`) 。 | | `languageCode` | `string` | 语言子标签 (例如 `'en'`) 。 | | `languageName` | `string` | 语言的英文名称 (例如 `'English'`) 。 | | `nativeLanguageName` | `string` | 该语言在其自身语言中的名称 (例如 `'English'`) 。 | | `nameWithRegionCode` | `string` | 包含地区的区域设置名称 (例如 `'English (US)'`) 。 | | `nativeNameWithRegionCode` | `string` | 包含地区的本地区域设置名称。 | | `regionCode` | `string` | 地区子标签 (例如 `'US'`) 。 | | `regionName` | `string` | 地区的英文名称 (例如 `'United States'`) 。 | | `nativeRegionName` | `string` | 该地区在区域设置自身语言中的名称。 | | `scriptCode` | `string` | 书写系统子标签 (例如 `'Latn'`) 。 | | `scriptName` | `string` | 书写系统的英文名称 (例如 `'Latin'`) 。 | | `nativeScriptName` | `string` | 该书写系统在区域设置自身语言中的名称。 | | `maximizedCode` | `string` | 完全展开的区域设置代码 (例如 `'en-Latn-US'`) 。 | *** ## 示例 ### 基本用法 ```js title="handler.js" import { getLocaleProperties } from 'gt-node'; app.get('/api/locale-info', (req, res) => { const props = getLocaleProperties('ja'); res.json({ name: props.name, // '日语' nativeName: props.nativeName, // '日本語' script: props.scriptName, // '日语' }); }); ``` *** ## 注意事项 * 此函数是同步的,无需使用 `await`。 * 可用于构建区域设置选择器,或向用户显示区域设置元数据。 ## 后续步骤 * 当前请求的区域设置请参阅 [`getLocale`](/docs/node/api/get-locale)。 * 详细了解[区域设置代码](/docs/core/locales)。