> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XPackageGetUserLocale

> XPackageGetUserLocale

# XPackageGetUserLocale

取得目前的使用者地區設定。

<a id="syntaxSection" />

## 語法

```cpp theme={null}
HRESULT XPackageGetUserLocale(
    size_t localeSize,
    char* locale
)  
```

<a id="parametersSection" />

### 參數

*localeSize*   \_In\_\
類型：size\_t

成功時，為 *locale* 中字串的大小。

*locale*   \_Out\_writes\_(localeSize)\
類型：char\*

成功時，包含使用者地區設定。

<a id="retvalSection" />

### 傳回值

類型：HRESULT

HRESULT 成功或錯誤碼。

<a id="remarksSection" />

## 備註

<Note>在時間敏感的執行緒上呼叫此函式並不安全。如需詳細資訊，請參閱[時間敏感的執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

此函式會取得最接近套件地區設定的使用者地區設定。如果套件未宣告任何地區設定資訊，此函式會成功，但不會在 `locale` 中傳回使用者地區設定。如果套件地區設定符合已安裝的使用者地區設定，此函式會成功，並在 `locale` 中傳回該使用者地區設定。如果套件地區設定與已安裝的使用者地區設定不完全相符，此函式會嘗試尋找最接近的已安裝使用者地區設定。如果此函式找不到相近的相符項目，就會發生錯誤；否則，此函式會成功，並在 `locale` 中傳回最接近的已安裝使用者地區設定。

如果您使用 Intelligent Delivery 控制為遊戲安裝哪些語言，使用者為主機設定的地區設定可能有目前尚未安裝的區塊。這要求遊戲必須一律確認所需的區塊已安裝，並在未安裝時改用其他語言：這個程序需要相當了解地區設定，以及它們如何回復為最接近的語言。此函式提供一種方式，讓您無需自行實作地區設定分析與回復程序，即可取得目前的使用者地區設定或最接近的回復地區設定。

下列程式碼範例示範如何使用此函式。

```cpp theme={null}
char gameLocale[LOCALE_NAME_MAX_LENGTH];

// Get the best user locale that is installed
HRESULT hr = XPackageGetUserLocale(_countof(gameLocale), gameLocale);
if (SUCCEEDED(hr))
{
    printf("Game using locale: %s\n", gameLocale);
}
```

<a id="requirementsSection" />

## 需求

**標頭：** XPackage.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機與 XBOX Series 主機

<a id="seealsoSection" />

## 概念文件

* [Intelligent Delivery：語言指定元](/zh-TW/build/core-features/common/packaging/intelligentdelivery-language)
* [時間敏感的執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)
* [判斷主機地區設定與語言](/zh-TW/build/game-principles/localization/determining-console-locale)

## 另請參閱

[XPackage](/zh-TW/reference/system/xpackage/xpackage_members)\
[串流安裝與 Intelligent Delivery](/zh-TW/build/core-features/common/packaging/overviews/streaming_install-intelligent_delivery)


## Related topics

- [XPackageGetUserLocale](/reference/system/xpackage/functions/xpackagegetuserlocale.md)
- [Determining console locale and language](/build/game-principles/localization/determining-console-locale.md)
- [Localization and globalization overview](/build/game-principles/localization.md)
- [Determinación de la configuración regional y el idioma de la consola](/es/build/game-principles/localization/determining-console-locale.md)
- [确定主机区域设置与语言](/zh-CN/build/game-principles/localization/determining-console-locale.md)
