# General Translation Platform: getLocaleProperties
URL: https://generaltranslation.com/zh/docs/platform/core/reference/gt-class-methods/locales/get-locale-properties.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 返回某个区域设置的详细语言、书写系统、区域和书写方向属性。getLocaleProperties 的 API 参考。

从 [GT](/docs/platform/core/reference/gt-class/constructor) 实例中获取某个区域设置代码的完整属性，包括显示名称、语言、书写系统、区域信息以及国旗 emoji。General Translation 会返回一个完整的 [`LocaleProperties`](/docs/platform/core/reference/types/locale-properties) 对象，其中包含构建丰富的国际化用户界面所需的数据。

## 概览 [#overview]

在 [`GT`](/docs/platform/core/reference/gt-class/constructor) 实例上调用 `getLocaleProperties` 时，可以选择传入区域设置代码。若省略，则使用该实例的 `targetLocale`。

```typescript
const gt = new GT({ sourceLocale: 'en', targetLocale: 'es' });

const props = gt.getLocaleProperties('fr-CA');
console.log(props.name); // "Canadian French"
console.log(props.nativeName); // "français canadien"
console.log(props.emoji); // "🇨🇦"
```

签名：

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

*注意：`getLocaleProperties` 在本地运行，不需要 API 密钥。省略 `locale` 时，它会使用该实例的 `targetLocale`，并且显示名称会遵循该实例的 `sourceLocale`。如果要在没有 `GT` 实例的情况下进行查找，请参阅独立的 [`getLocaleProperties`](/docs/platform/core/reference/utility-functions/locales/get-locale-properties)。*

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

* **最大化和最小化形式。** 该方法会推导出区域设置代码的最大化形式 (补全可能的书写系统和区域) 以及最小化形式。
* **显示语言。** 所有显示名称都遵循实例的 `sourceLocale` 设置。
* **自定义映射优先级。** 在 [`CustomMapping`](/docs/platform/core/reference/types/custom-mapping) 中定义的属性优先于标准 `Intl` API。
* **区域设置后备。** 省略 `locale` 时，将使用实例的 `targetLocale`。
* **缺少区域设置。** 如果未提供 `locale`，且实例未配置 `targetLocale`，则会抛出 `Error`。

## 参数 [#parameters]

| 参数                  | 描述                     | 类型       | 可选 | 默认值                 |
| ------------------- | ---------------------- | -------- | -- | ------------------- |
| [`locale`](#locale) | 要获取其属性的 BCP-47 区域设置代码。 | `string` | 是  | `this.targetLocale` |

### `locale` [#locale]

**类型** `string` · **可选** · **默认值** `this.targetLocale`

用于获取属性的 BCP-47 区域设置代码 (例如 `"de-AT"`) 。如果未提供，则使用实例的 `targetLocale`。

## 返回值 [#returns]

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

一个用于完整描述区域设置的对象：

* `code`：完整的区域设置代码 (例如 `"de-AT"`) 。
* `name`：以显示语言显示的语言名称 (例如 `"Austrian German"`) 。
* `nativeName`：以该区域设置的本地语言显示的语言名称 (例如 `"Österreichisches Deutsch"`) 。
* `languageCode`, `languageName`, `nativeLanguageName`：基础语言信息。
* `nameWithRegionCode`, `nativeNameWithRegionCode`：带区域代码的语言名称 (例如 `"German (AT)"`) 。
* `regionCode`, `regionName`, `nativeRegionName`：区域信息。
* `scriptCode`, `scriptName`, `nativeScriptName`：书写系统信息。
* `maximizedCode`, `maximizedName`, `nativeMaximizedName`：包含可能的书写系统和区域的最大化形式。
* `minimizedCode`, `minimizedName`, `nativeMinimizedName`：最小化形式。
* `emoji`：该区域设置所属区域的旗帜或代表性 emoji。

如果未提供区域设置，且该实例未配置 `targetLocale`，则会抛出 `Error`。

## 示例 [#examples]

```typescript
// 基本用法
const gt = new GT({ sourceLocale: 'en', targetLocale: 'fr' });

// 获取目标区域设置的属性
const props = gt.getLocaleProperties();
console.log(props.name); // "French"
console.log(props.nativeName); // "français"
console.log(props.languageCode); // "fr"
console.log(props.regionCode); // "FR"
console.log(props.emoji); // "🇫🇷"

// 获取其他区域设置的属性
const germanProps = gt.getLocaleProperties('de-AT');
console.log(germanProps.name); // "Austrian German"
console.log(germanProps.nativeName); // "Österreichisches Deutsch"
console.log(germanProps.regionName); // "Austria"
console.log(germanProps.nativeRegionName); // "Österreich"
```

## 备注 [#notes]

* 所有显示名称均以实例的 `sourceLocale` 设置为准。
* 自定义映射属性的优先级高于标准 `Intl` API。

## Sitemap

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