From 176c4545f626f74d34cb441c5f254d09dd63eb91 Mon Sep 17 00:00:00 2001 From: Georg Bauer Date: Wed, 12 Oct 2005 11:48:27 +0000 Subject: [PATCH] changed layout of language stuff to be oriented after locale names, not language names (from accept-language header) git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@848 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- .../{pt-br => pt_BR}/LC_MESSAGES/django.mo | Bin .../{pt-br => pt_BR}/LC_MESSAGES/django.po | 0 django/utils/translation.py | 10 ++++----- docs/translation.txt | 20 +++++++++++++----- 4 files changed, 19 insertions(+), 11 deletions(-) rename django/conf/locale/{pt-br => pt_BR}/LC_MESSAGES/django.mo (100%) rename django/conf/locale/{pt-br => pt_BR}/LC_MESSAGES/django.po (100%) diff --git a/django/conf/locale/pt-br/LC_MESSAGES/django.mo b/django/conf/locale/pt_BR/LC_MESSAGES/django.mo similarity index 100% rename from django/conf/locale/pt-br/LC_MESSAGES/django.mo rename to django/conf/locale/pt_BR/LC_MESSAGES/django.mo diff --git a/django/conf/locale/pt-br/LC_MESSAGES/django.po b/django/conf/locale/pt_BR/LC_MESSAGES/django.po similarity index 100% rename from django/conf/locale/pt-br/LC_MESSAGES/django.po rename to django/conf/locale/pt_BR/LC_MESSAGES/django.po diff --git a/django/utils/translation.py b/django/utils/translation.py index 96c98f691a..0ffd4a2e43 100644 --- a/django/utils/translation.py +++ b/django/utils/translation.py @@ -271,6 +271,9 @@ def get_language_from_request(request): else: lang = el order = 100 + if lang.find('-') >= 0: + (lang, sublang) = lang.split('-') + lang = lang.lower() + '_' + sublang.upper() return (lang, order) langs = [_parsed(el) for el in accept.split(',')] @@ -279,14 +282,9 @@ def get_language_from_request(request): globalpath = os.path.join(os.path.dirname(settings.__file__), 'locale') for lang, order in langs: - if lang == 'en' or os.path.isfile(os.path.join(globalpath, lang, 'LC_MESSAGES', 'django.mo')): + if lang == 'en' or lang.startswith('en_') or gettext_module.find('django', globalpath, [lang]): _accepted[accept] = lang return lang - elif lang.find('-') >= 0: - (lang, sublang) = lang.split('-', 1) - if lang == 'en' or os.path.isfile(os.path.join(globalpath, lang, 'LC_MESSAGES', 'django.mo')): - _accepted[accept] = lang - return lang return settings.LANGUAGE_CODE diff --git a/docs/translation.txt b/docs/translation.txt index 2a95286e0e..37d2bc2385 100644 --- a/docs/translation.txt +++ b/docs/translation.txt @@ -179,11 +179,18 @@ If neither GET nor POST have django_language, the middleware looks at the session data for the user. If that carries a key django_language, it's contents will be used as the language code. If the session doesn't contain a language setting, the middleware will look at the cookies for a django_language cookie. -If that is found, it gives the language code. If neither the session nor the -cookie carry a language code, the middleware will look at the HTTP header -Accept-Language. This header is sent by your browser and tells the server what -languages you prefer. Languages are ordered by some choice value - the higher, -the more you prefer the language. +If that is found, it gives the language code. + +The format for the explicit django_language parameters is allways the +locale to use - for example it's pt_BR for Brazilian. If a base language +is available, but the sublanguage specified is not, the base language is used. +For example if you specify de_AT (Austrian German), but there is only a +language de available, that language is used. + +If neither the session nor the cookie carry a language code, the middleware +will look at the HTTP header Accept-Language. This header is sent by your +browser and tells the server what languages you prefer. Languages are ordered +by some choice value - the higher, the more you prefer the language. So the middleware will iterate over that header, ordered by the preference value. The language with the highest preference that is in the django base @@ -231,6 +238,9 @@ might be that it is utf-8 - if you prefer another encoding, you can use some tools like recode or iconv to change the charset of the file and then change the charset definition in the file (it's in the Content-Type: line). +The language code for storage is in locale format - so it is pt_BR for +Brazilian or de_AT for Austrian German. + Every message in the message file is of the same format. One line is the msgid. This is the actual string in the source - you don't change it. The other line is msgstr - this is the translation. It starts out empty. You change it.