#28636: Translation module: Check `LANG_INFO` against user's language preference as optional feature -------------------------------------+------------------------------------- Reporter: Denis Anuschewski | Owner: nobody Type: New feature | Status: new Component: | Version: 1.11 Internationalization | Severity: Normal | Resolution: Keywords: translation, | Triage Stage: internationalization, request | Unreviewed Has patch: 1 | Needs documentation: 1 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Denis Anuschewski): Thx again. I tested your code and it really does exactly what I want! You were right that I don't really need to know the request language if it's not in `LANGUAGES`, because the resulting language is always 'en' for these cases. So my custom middleware's `process_request` would look like this: {{{ def process_request(self, request): self.fallback_language = 'en' super(CustomMiddleWare, self).process_request(request) lan = request.LANGUAGE_CODE if not settings.LANGUAGE_CODE.startswith(lan): translation.trans_real.translation(lan).add_fallback(DjangoTranslation(self.fallback_language)) }}} Therefore I get either `LANGUAGE_CODE`, English or a language from `LANGUAGES` with English translation fallback. Bingo! Your approach seems cleaner and more readable for me, plus it affects less code. But there is one little thing I am missing: I would like to see an additional paragraph in the docstring of `get_language_from_request` describing what fallback does. I would suggest something like this: {{{ With a given fallback, this value will be returned instead of settings.LANGUAGE_CODE if no user language could be found. }}} Otherwise I am not missing anything. If you make a pull request with the little addition I mentioned, I am more than happy to declare it as a fix for this bug and vote for it. -- Ticket URL: <https://code.djangoproject.com/ticket/28636#comment:15> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.458b701852ccb10244484b1d768bc13c%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.