Django

Code

Changeset 848

Show
Ignore:
Timestamp:
10/12/05 06:48:27 (3 years ago)
Author:
hugo
Message:

changed layout of language stuff to be oriented after locale names, not language names (from accept-language header)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/i18n/django/utils/translation.py

    r841 r848  
    272272                lang = el 
    273273                order = 100 
     274            if lang.find('-') >= 0: 
     275                (lang, sublang) = lang.split('-') 
     276                lang = lang.lower() + '_' + sublang.upper() 
    274277            return (lang, order) 
    275278 
     
    280283 
    281284        for lang, order in langs: 
    282             if lang == 'en' or os.path.isfile(os.path.join(globalpath, lang, 'LC_MESSAGES', 'django.mo')): 
     285            if lang == 'en' or lang.startswith('en_') or gettext_module.find('django', globalpath, [lang]): 
    283286                _accepted[accept] = lang 
    284287                return lang 
    285             elif lang.find('-') >= 0: 
    286                 (lang, sublang) = lang.split('-', 1) 
    287                 if lang == 'en' or os.path.isfile(os.path.join(globalpath, lang, 'LC_MESSAGES', 'django.mo')): 
    288                     _accepted[accept] = lang 
    289                     return lang 
    290288     
    291289    return settings.LANGUAGE_CODE 
  • django/branches/i18n/docs/translation.txt

    r840 r848  
    180180will be used as the language code. If the session doesn't contain a language 
    181181setting, the middleware will look at the cookies for a django_language cookie. 
    182 If that is found, it gives the language code. If neither the session nor the 
    183 cookie carry a language code, the middleware will look at the HTTP header 
    184 Accept-Language. This header is sent by your browser and tells the server what 
    185 languages you prefer. Languages are ordered by some choice value - the higher, 
    186 the more you prefer the language. 
     182If that is found, it gives the language code. 
     183 
     184The format for the explicit django_language parameters is allways the 
     185locale to use - for example it's pt_BR for Brazilian. If a base language 
     186is available, but the sublanguage specified is not, the base language is used. 
     187For example if you specify de_AT (Austrian German), but there is only a 
     188language de available, that language is used. 
     189 
     190If neither the session nor the cookie carry a language code, the middleware 
     191will look at the HTTP header Accept-Language. This header is sent by your 
     192browser and tells the server what languages you prefer. Languages are ordered 
     193by some choice value - the higher, the more you prefer the language. 
    187194 
    188195So the middleware will iterate over that header, ordered by the preference 
     
    231238tools like recode or iconv to change the charset of the file and then change 
    232239the charset definition in the file (it's in the Content-Type: line). 
     240 
     241The language code for storage is in locale format - so it is pt_BR for 
     242Brazilian or de_AT for Austrian German. 
    233243 
    234244Every message in the message file is of the same format. One line is the msgid.