get_language_from_request
Analyze the request to find what language the user wants the system to show. Only languages listed in settings.LANGUAGES are taken into account. If the user requests a sublanguage where we have a main language, we send out the main language. If check_path is True, the URL path prefix will be checked for a language code, otherwise this is skipped for backwards compatibility.
def get_language_from_request(
request: HttpRequest,
check_path: boolean = False
) - > string
Analyze the request to find what language the user wants the system to show. Only languages listed in settings.LANGUAGES are taken into account. If the user requests a sublanguage where we have a main language, we send out the main language. If check_path is True, the URL path prefix will be checked for a language code, otherwise this is skipped for backwards compatibility.
Parameters
| Name | Type | Description |
|---|---|---|
| request | HttpRequest | The incoming HTTP request object containing metadata, cookies, and path information used to determine the user's language preference. |
| check_path | boolean = False | A flag indicating whether to inspect the URL path prefix for a language code before checking cookies and headers. |
Returns
| Type | Description |
|---|---|
string | The preferred language code (e.g., 'en' or 'pt-br') that matches the user's request and is supported by the system settings. |