#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):
Replying to [comment:6 Claude Paroz]:
> > You could use that e.g. for comparing with settings.LANGUAGE_CODE and
add a fallback for specific cases.
>
> Could you please elaborate a bit more about the use case for that
request?
Yes of course.
Let's say we have following settings:
{{{
LANGUAGE_CODE = 'de-DE'
LANGUAGES = [
('en', 'English'),
('de', 'German'),
('es', 'Spanish'),
}}}
So we have German as standard language and the 3 languages in
`settings.LANGUAGES` as those which we want to have translated. And now
imagine we want to have a custom middleware that looks something like
this:
{{{
class CustomLocaleMiddleware(LocaleMiddleware):
def process_request(self, request):
super(CustomLocaleMiddleware, self).process_request(request)
lan = request.LANGUAGE_CODE
preference = translation.get_language_from_request(request,
support_all_languages=True)
if not settings.LANGUAGE_CODE.startswith(preference): #
Preference differs from LANGUAGE_CODE
translation.trans_real.translation(lan).add_fallback(
translation.trans_real.DjangoTranslation('en'))
}}}
So every language preference that gets identified by
`get_language_from_request` and differs from `settings.LANGUAGE_CODE` gets
English as fallback language, even if it's not in `settings.LANGUAGES`.
When you get e.g. ''pl'' as preference you get ''de'' as language, but
with ''en'' as fallback (that's what we want). With current Django you
would also get ''de'' as language, but no fallback because preference
would not be ''pl'' but ''de''. It would only work with "en", "de", and
"es".
--
Ticket URL: <https://code.djangoproject.com/ticket/28636#comment:7>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.32095f013f58e6f0e9afc98a9e8966e8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.