# General Translation Python SDKs: get_locale
URL: https://generaltranslation.com/zh/docs/python/reference/functions/get-locale.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 在 General Translation Python 中读取当前请求的活动区域设置。get_locale 的 API 参考。

返回为当前请求解析出的区域设置。它会读取区域设置检测存储在当前活动 [`I18nManager`](/docs/python/reference/classes/i18n-manager) 上的值。

## 概览 [#overview]

调用不带任何参数的 `get_locale`，即可获取当前区域设置代码。

```python
from gt_flask import get_locale  # 或：from gt_fastapi import get_locale，或：from gt_i18n import get_locale

locale = get_locale()  # 例如 "es"
```

签名：

```python
get_locale() -> str
```

*注意：它会读取当前处于激活状态的管理器，因此必须先运行 [`initialize_gt`](/docs/python/reference/functions/initialize-gt) (或 [`set_i18n_manager`](/docs/python/reference/functions/set-i18n-manager)) ，否则会抛出 `RuntimeError`。*

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

* **请求级别。** 它会返回当前请求中由区域设置检测保存的区域设置 (通过管理器的存储适配器) 。
* **后备。** 如果未设置请求的区域设置，则会回退到默认区域设置。

## 参数 [#parameters]

`get_locale` 不需要任何参数。

## 返回值 [#returns]

**类型** `str`

当前区域设置代码。

## 示例 [#example]

```python
from gt_flask import get_locale

locale = get_locale()  # 例如 "es"
```

## Sitemap

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