Skip to main content

get_language_from_request

Analyzes the request to find the language the user wants the system to show.

def get_language_from_request(
request: HttpRequest,
check_path: boolean = False
) - > string

Determines the preferred language for the current request by inspecting the request object and optionally the URL path.

Parameters

NameTypeDescription
requestHttpRequestThe incoming HTTP request object containing headers, cookies, and session data used for language discovery.
check_pathboolean = FalseWhether to examine the URL path prefix to determine the requested language.

Returns

TypeDescription
stringThe language code identified from the request, such as 'en' or 'fr', used to set the translation context.