Hi everybody,

we just finished developing a major multi-language site for a customer. In 
the course of this development, we run into two issues with the PO files 
which I haven't been able to find either on the mailing list or in the bug 
tracker so I'll raise them here:

We're using country-specific translations as well as a fallback 
translation, for instance "de-de" (Germany) and "de-ch" (Switzerland) as 
well as the global "de" (German) translation. In case the country-specific 
translation doesn't exist or does not contain a certain string, it should 
fall back to the global version. However, while 
django.utils.translation.trans_real talks about fallbacks (for instance 
here: 
https://github.com/django/django/blob/master/django/utils/translation/trans_real.py#L142),
 
the actual fallback does not happen. If the country-specific locale does 
not exist, the global version is not being used either.

We solved it with this middleware:

    from django.middleware.locale import LocaleMiddleware
    from django.utils.translation.trans_real import _translations, 
translation
    
    
    class FallbackLocaleMiddleware(LocaleMiddleware):
        def process_request(self, request):
            super(FallbackLocaleMiddleware, self).process_request(request)
            if '-' in request.LANGUAGE_CODE:
                trans = _translations[request.LANGUAGE_CODE]
                if not trans._fallback:
                    
trans.add_fallback(translation(request.LANGUAGE_CODE.split('-', 1)[0]))

I think the culprit is this line: 
https://github.com/django/django/blob/master/django/utils/translation/trans_real.py#L177

Shouldn't this rather be something along the lines of:

    if '-' in language:
        default_translation = _fetch(language.split('-')[0]) or 
_fetch(settings.LANGUAGE_CODE)
    else:
        default_translation = _fetch(settings.LANGUAGE_CODE)

I might be misunderstanding the Django translation logic so I wanted to 
raise this issue here before filing a ticket. Feedback is very welcome.

Cheers,

  Jonas


-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" 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].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to