> ## 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.

# Determining console locale and language

> Use GetUserDefaultLocaleName and XPackageGetUserLocale to detect the XBOX console language and load the closest matching localized resources in your GDK title.

Retrieve the locale of the signed-in session with [`GetUserDefaultLocaleName`](https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-getuserdefaultlocalename):

```cpp theme={null}
wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
int retVal = GetUserDefaultLocaleName(localeName, ARRAYSIZE(localeName));
// The value is returned in localeName.
```

Games usually don't care about the exact locale — they care about **which language resources to load**. Pick the language in the game's package that is "closest" to what the user selected. Three inputs matter:

1. Languages declared in `MicrosoftGame.config`.
2. Languages declared in the package layout file.
3. Language selected on the device.

Use [`XPackageGetUserLocale`](/reference/system/xpackage/functions/xpackagegetuserlocale) to always get the closest supported language:

```cpp theme={null}
char gameLocale[LOCALE_NAME_MAX_LENGTH];
HRESULT hr = XPackageGetUserLocale(_countof(gameLocale), gameLocale);
if (SUCCEEDED(hr))
{
    printf("Game using locale: %s\n", gameLocale);
}
```

## Examples

### 1. User locale matches a supported resource

User selects **French / France (fr-FR)**. `MicrosoftGame.config`:

```xml theme={null}
<Resources>
    <Resource Language="en-US"/>
    <Resource Language="fr-FR"/>
    <Resource Language="de-DE"/>
    <Resource Language="en-GB"/>
</Resources>
```

* `XPackageGetUserLocale` returns `fr-FR`.
* `GetUserDefaultLocaleName` returns `fr-FR`.

### 2. User locale not in manifest, but same language exists

User selects **English / UK (en-GB)**. `MicrosoftGame.config`:

```xml theme={null}
<Resources>
    <Resource Language="en-US"/>
    <Resource Language="fr-FR"/>
    <Resource Language="de-DE"/>
</Resources>
```

* `XPackageGetUserLocale` returns `en-US` (fallback within same language).
* `GetUserDefaultLocaleName` returns `en-GB` (always the console value).

### 3. User language not present at all

User locale is `fr-FR`. `MicrosoftGame.config`:

```xml theme={null}
<Resources>
    <Resource Language="en-US"/>
    <Resource Language="de-DE"/>
</Resources>
```

* `XPackageGetUserLocale` returns `en-US` (first entry in `Resources`).
* `GetUserDefaultLocaleName` returns `fr-FR`.

## Summary

* `GetUserDefaultLocaleName` — what the console is set to, ignoring the game's declared languages.
* `XPackageGetUserLocale` — which language to load, using this logic:
  1. If user's locale is in `MicrosoftGame.config`, return it.
  2. Otherwise find a same-language locale in the manifest (best fallback based on user's locale).
  3. Otherwise return the first locale in `Resources`.
  4. If no languages are listed, return the console language.

## See also

* [XPackageGetUserLocale](/reference/system/xpackage/functions/xpackagegetuserlocale)
* [MicrosoftGame.config localization](/build/core-features/common/game-config/MicrosoftGameConfig-Localization)

## Related API documentation

* [XGameRuntime features reference](/reference/system/xgameruntimefeature/xgameruntimefeature_members) — `XGameRuntimeLocale` for the active locale
* [XPackage API reference](/reference/system/xpackage/xpackage_members) — locale-aware package resource queries


## Related topics

- [XPackageGetUserLocale](/reference/system/xpackage/functions/xpackagegetuserlocale.md)
- [Localization and globalization overview](/build/game-principles/localization.md)
- [Determining console location](/build/game-principles/localization/determining-console-geolocation.md)
- [Console-supported languages](/build/game-principles/localization/console-supported-languages.md)
- [Game-supported and unsupported locales](/build/game-principles/localization/game-supported-and-unsupported-locales.md)
