You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Enhance LanguageMiddleware with improved language detection and validation
- Added support for multiple language detection sources in LanguageMiddleware:
query parameters (`?lang=xx`), user profile preference, cookies, and Accept-Language header.
- Introduced `LISAN_ALLOWED_LANGUAGES` setting to restrict accepted languages to a configurable list.
- Fallback to `LISAN_DEFAULT_LANGUAGE` when no valid language is detected or if the requested language is not supported.
- Improved parsing of the Accept-Language header to handle complex cases (e.g., "en-US,en;q=0.9").
- Ensured safe retrieval of user profile language preferences to avoid potential errors.
- Added validation to ensure selected language is within supported languages.
- Updated default behavior to gracefully handle missing or malformed headers and attributes.
Copy file name to clipboardexpand all lines: CHANGELOG.md
+28
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,31 @@
1
+
## [v0.1.2] - 2024-10-05
2
+
3
+
This release focuses on refining the multilingual handling capabilities by introducing additional flexibility in language detection and ensuring compatibility with supported languages.
4
+
5
+
### Added
6
+
-**Enhanced Language Detection in Middleware**:
7
+
-**Improved `LanguageMiddleware`**: The `LanguageMiddleware` now includes more robust language detection mechanisms:
8
+
- It checks for the `lang` query parameter, user profile language preference, cookies, and the `Accept-Language` header in a prioritized manner.
9
+
- Added support for configurable fallback languages via the `LISAN_DEFAULT_LANGUAGE` setting.
10
+
- Introduced validation to ensure the selected language is within the list of supported languages, using the new `LISAN_ALLOWED_LANGUAGES` setting.
11
+
- Refined the `Accept-Language` header parsing to handle complex header values and gracefully fallback when necessary.
12
+
13
+
-**Support for Configurable Allowed Languages**: A new setting, `LISAN_ALLOWED_LANGUAGES`, has been added to specify the languages supported by the application. If a language from the request is not in this list, the middleware falls back to the default language.
14
+
15
+
### Configuration Changes
16
+
-**New Settings**:
17
+
-`LISAN_ALLOWED_LANGUAGES`: A list of language codes that the application supports. The `LanguageMiddleware` ensures that only these languages are applied to the request. Defaults to `[LISAN_DEFAULT_LANGUAGE]`.
18
+
19
+
### Fixed
20
+
- Improved robustness in the `LanguageMiddleware` by ensuring safe access to user profile attributes and handling of missing or malformed `Accept-Language` headers.
21
+
- Prevented invalid language codes from being set on requests by validating against the new `LISAN_ALLOWED_LANGUAGES` setting.
22
+
23
+
### Migration Notes
24
+
No database migrations are required for this release. However, to take advantage of the new language validation features, developers should define `LISAN_ALLOWED_LANGUAGES` in `settings.py`.
25
+
26
+
---
27
+
28
+
1
29
## [v0.1.1] - 2024-09-14
2
30
3
31
This version brings enhanced flexibility, making the `lisan` package highly adaptable for multilingual projects by enabling external services for automated translations while maintaining a customizable architecture.
0 commit comments