This release focuses on refining the multilingual handling capabilities by introducing additional flexibility in language detection and ensuring compatibility with supported languages.
- Enhanced Language Detection in Middleware:
-
Improved
LanguageMiddleware
: TheLanguageMiddleware
now includes more robust language detection mechanisms:- It checks for the
lang
query parameter, user profile language preference, cookies, and theAccept-Language
header in a prioritized manner. - Added support for configurable fallback languages via the
LISAN_DEFAULT_LANGUAGE
setting. - Introduced validation to ensure the selected language is within the list of supported languages, using the new
LISAN_ALLOWED_LANGUAGES
setting. - Refined the
Accept-Language
header parsing to handle complex header values and gracefully fallback when necessary.
- It checks for the
-
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.
-
- New Settings:
LISAN_ALLOWED_LANGUAGES
: A list of language codes that the application supports. TheLanguageMiddleware
ensures that only these languages are applied to the request. Defaults to[LISAN_DEFAULT_LANGUAGE]
.
- Improved robustness in the
LanguageMiddleware
by ensuring safe access to user profile attributes and handling of missing or malformedAccept-Language
headers. - Prevented invalid language codes from being set on requests by validating against the new
LISAN_ALLOWED_LANGUAGES
setting.
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
.
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.
-
Pluggable Translation Service: Introduced a base
BaseTranslationService
class, allowing easy integration of third-party or custom translation services.- Added an example implementation with
GoogleTranslateService
using Google’s translation API. - Enabled dynamic loading of translation services via Django settings (
LISAN_DEFAULT_TRANSLATION_SERVICE
).
- Added an example implementation with
-
Auto-Translation Support:
- Added an
auto_translate
option toget_lisan_field
inLisanModelMixin
, enabling automatic translation fallback when specific language translations are missing. - Added auto-translation support in serializers and admin displays for models with translatable fields.
- Added an
-
Bulk Translation Operations: Added
set_bulk_lisans
method to support creating or updating translations for multiple languages in bulk. -
Flexible Field Types: Enhanced support for additional field types, such as
TextField
,JSONField
, and more, in translatable models. -
Customizable Admin Display:
- Introduced
lisan_display_format
for customizing how translated fields appear in the Django admin interface.
- Introduced
-
Middleware Improvement: Enhanced
LanguageMiddleware
to support multiple language detection sources, including query parameters (?lang=xx
), cookies, and user profile settings.
- Improved fallback language handling for missing translations, with a new configuration (
LISAN_FALLBACK_LANGUAGES
) allowing developers to define custom fallback hierarchies.
- New Settings:
LISAN_DEFAULT_TRANSLATION_SERVICE
: Configure the default translation service dynamically.LISAN_FALLBACK_LANGUAGES
: Customize fallback languages in case a specific translation is missing.
No database migrations are required for this release, but additional configuration in settings.py
may be necessary to leverage new features like auto-translation and pluggable services.
- Introduce caching for external translation service results to minimize API calls.
- Add support for other translation services such as DeepL and Microsoft Translator.
- Improve manual translation management in the Django admin interface.