# gt-node: General Translation Node.js SDK: getLocaleProperties
URL: https://generaltranslation.com/zh/docs/node/reference/functions/get-locale-properties.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 读取 General Translation gt-node 中某个区域设置的显示元数据。getLocaleProperties 的 API 参考。

返回某个区域设置的元数据，包括其名称、本地名称、语言、地区和书写系统信息。你可以用它来构建区域设置选择器，或向用户显示区域设置元数据。

## 概览 [#overview]

调用 `getLocaleProperties` 时可传入区域设置代码；如果不传参数，则使用当前区域设置。它会返回一个 [`LocaleProperties`](/docs/platform/core/reference/types/locale-properties) 对象。

```ts
import { getLocaleProperties } from 'gt-node';

const props = getLocaleProperties('en-US');
console.log(props.name); // 'American English'
```

签名：

```ts
getLocaleProperties(locale?: string): LocaleProperties
```

*注意：此函数是同步函数，无需使用 await。*

## 工作原理 [#how-it-works]

* **区域设置回退。** 省略 `locale` 时，它指当前区域设置。
* **派生子标签。** 它会解析语言、书写系统和地区子标签及其显示名称，以及最大化形式。
* **同步。** 它会立即返回，无需发起网络请求。

## 参数 [#parameters]

| 参数                  | 描述                  | 类型       | 可选 | 默认值    |
| ------------------- | ------------------- | -------- | -- | ------ |
| [`locale`](#locale) | 要说明的 BCP 47 区域设置代码。 | `string` | 是  | 当前区域设置 |

### `locale` [#locale]

**类型** `string` · **可选** · **默认值** 当前区域设置

BCP 47 区域设置代码 (例如：`'en-US'`、`'ja'`) 。未提供时，使用当前区域设置。

## 返回值 [#returns]

**类型** [`LocaleProperties`](/docs/platform/core/reference/types/locale-properties)

一个 [`LocaleProperties`](/docs/platform/core/reference/types/locale-properties) 对象，包含以下字段：

| 字段                         | 类型       | 描述                                                  |
| -------------------------- | -------- | --------------------------------------------------- |
| `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'`) 。                  |
| `maximizedName`            | `string` | 完全展开后的区域设置的英文名称 (例如 `'American English (Latin)'`) 。 |
| `nativeMaximizedName`      | `string` | 完全展开后的区域设置以自身语言表示的名称。                               |
| `minimizedCode`            | `string` | 最简区域设置代码 (例如 `'en'`) 。                              |
| `minimizedName`            | `string` | 最简区域设置的英文名称。                                        |
| `nativeMinimizedName`      | `string` | 最简区域设置以自身语言表示的名称。                                   |
| `emoji`                    | `string` | 该区域设置对应的旗帜或代表性 emoji。                               |

## 示例 [#examples]

```ts title="handler.js"
// 基本用法
import { getLocaleProperties } from 'gt-node';

app.get('/api/locale-info', (req, res) => {
  const props = getLocaleProperties('ja');
  res.json({
    name: props.name,             // 'Japanese'
    nativeName: props.nativeName, // '日本語'
    script: props.scriptName,     // 'Japanese'
  });
});
```

## 注意事项 [#notes]

* 此函数是同步的——无需 `await`。
* 可用于构建区域设置选择器，或向用户展示区域设置元数据。

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
