--
Everything is worth doing is worth doing well!
Wayne's Geek Life http://WayneYe.com
Infinite Passion On Programming!
Per official I18n wiki: https://docs.djangoproject.com/en/1.4/topics/i18n/translation/#using-translations-outside-views-and-templatesI was using translation.get_language() method to retrieve the client preferred language:class IndexView(generic.TemplateView):def get(self, request):cur_language = translation.get_language()print('='*50)print('Current locale: ' + cur_language)print('='*50)return render(request, 'myapp/index.html', {}, context_instance=RequestContext(request))By hitting view above I noticed that django actually does not correctly recognise all lower-cased language tag (such as zh-cn), I did change your testing code a little bit to below and it will fail:r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4'}self.assertEqual('zh-tw', g(r))self.assertEqual('zh-tw', get_language())r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-tw,zh;q=0.8,en-us;q=0.5,en;q=0.3'}self.assertEqual('zh-tw', g(r))self.assertEqual('zh-tw', get_language())So I am thinking will it be better to use get_language_from_request() instead of get_language(), i.e.:cur_language = translation.get_language_from_request(request)
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/32345674-3256-4204-91ac-66bfc5869213%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
> I wonder if this also has implications for checking whether a given
> locale is present on the system. It looks to me like we also do this
> case-sensitively right now, but we should do it case-insensitively. This
> might be a bit of work, since it would mean that rather than just
> checking for the existence of a particular locale directory as we do
> now, we would need to read in all the available locale names into memory
> (presuming we can't/don't want to enforce that all locales on disk are
> lower-cased or whatever).
The names of directories with translations on disk are actually GNU
gettext locale names[1] as opposed to language names[1] (the ones in
the Accept-Language HTTP header and discussed above.)
It does specify that the part after the underscore separator must be a
ISO 3166 country code. See [2] and [3].
So, for me, this indicates Django current behavior with these file
system dir names is correct. But perhaps I'm missing something?