Compartir a través de


XPackageGetUserLocale

Gets the current user locale.

Syntax

HRESULT XPackageGetUserLocale(
    size_t localeSize,
    char* locale
)  

Parameters

localeSize   _In_
Type: size_t

On success, the size of the string in locale.

locale   _Out_writes_(localeSize)
Type: char*

On success, contains the user locale.

Return value

Type: HRESULT

HRESULT success or error code.

Remarks

Note

This function isn't safe to call on a time-sensitive thread. For more information, see Time-sensitive threads.

This function gets the user locale that most closely matches the package locale. If no locale information is declared for the package, this function succeeds but does not return a user locale in locale. If the package locale matches an installed user locale, the function succeeds and returns the user locale in locale. If the package locale does not exactly match an installed user locale, the function attempts to find the closest matching installed user locale. If the function cannot find a close match, an error occurs; otherwise, the function succeeds and the closest matching installed user locale is returned in locale.

If you are using Intelligent Delivery to control which languages are installed for your game, it's possible that the locale to which the user has set the console has chunks that are not currently installed. This requires a game to always verify that the necessary chunks are installed, and to fall back to another language if they are not: a procedure that requires considerable knowledge about locales and how they fall back to their closest languages. This function provides a way to get the current user locale, or the closest matching fallback, without the need to implement your own locale analysis and fallback procedure.

The following code sample demonstrates how to use this function.

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);
}

Requirements

Header: XPackage.h

Library: xgameruntime.lib

Supported platforms: Windows, Xbox One family consoles and Xbox Series consoles

See also

XPackage
Streaming Installation and Intelligent Delivery