Changeset 914
- Timestamp:
- 10/17/05 14:33:30 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/i18n/django/conf/global_settings.py
r898 r914 27 27 # http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes 28 28 # http://blogs.law.harvard.edu/tech/stories/storyReader$15 29 # Language codes need to be given in locale format, not in HTML language 30 # format. So it's en_US and not en-us to store here. The HTML language 31 # is stored in the request.LANGUAGE_CODE variable and will depend on the 32 # users browser. 33 LANGUAGE_CODE = 'en' 29 LANGUAGE_CODE = 'en-us' 34 30 35 31 # Languages we provide translations for out of the base. The django/branches/i18n/django/conf/project_template/settings/main.py
r898 r914 9 9 MANAGERS = ADMINS 10 10 11 LANGUAGE_CODE = 'en _US'11 LANGUAGE_CODE = 'en-us' 12 12 13 13 DATABASE_ENGINE = 'postgresql' # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. django/branches/i18n/django/core/extensions.py
r869 r914 37 37 self['LANGUAGES'] = settings.LANGUAGES 38 38 if hasattr(request, 'LANGUAGE_CODE'): 39 self['LANGUAGE_CODE'] = request.LANGUAGE_CODE .replace('_', '-')39 self['LANGUAGE_CODE'] = request.LANGUAGE_CODE 40 40 else: 41 self['LANGUAGE_CODE'] = settings.LANGUAGE_CODE .replace('_', '-')41 self['LANGUAGE_CODE'] = settings.LANGUAGE_CODE 42 42 if DEBUG and request.META.get('REMOTE_ADDR') in INTERNAL_IPS: 43 43 self['debug'] = True django/branches/i18n/django/utils/translation.py
r904 r914 32 32 # run multiple times for one user 33 33 _accepted = {} 34 35 def to_locale(language): 36 "turn a language name (en-us) into a locale name (en_US)" 37 p = language.find('-') 38 if p >= 0: 39 return language[:p].lower()+'_'+language[p:].upper() 40 else: 41 return language.lower() 42 43 def to_language(locale): 44 "turns a locale name (en_US) into a language name (en-us)" 45 p = locale.find('_') 46 if p >= 0: 47 return locale[:p].lower()+'-'+locale[p:].lower() 48 else: 49 return locale.lower() 34 50 35 51 class DjangoTranslation(gettext_module.GNUTranslations): … … 105 121 from django.conf import settings 106 122 123 default_locale = to_locale(settings.LANGUAGE_CODE) 124 locale = to_locale(language) 125 107 126 # set up the right translation class 108 127 klass = DjangoTranslation … … 113 132 114 133 try: 115 t = gettext_module.translation('django', globalpath, [l anguage, settings.LANGUAGE_CODE], klass)134 t = gettext_module.translation('django', globalpath, [locale, default_locale], klass) 116 135 t.set_app_and_language(appname, language) 117 136 except IOError: t = gettext_module.NullTranslations() … … 121 140 for localepath in settings.LOCALE_PATHS: 122 141 try: 123 t = gettext_module.translation('django', localepath, [l anguage, settings.LANGUAGE_CODE], klass)142 t = gettext_module.translation('django', localepath, [locale, default_locale], klass) 124 143 t.set_app_and_language(appname, language) 125 144 except IOError: t = None … … 134 153 135 154 try: 136 t = gettext_module.translation('django', projectpath, [l anguage, settings.LANGUAGE_CODE], klass)155 t = gettext_module.translation('django', projectpath, [locale, default_locale], klass) 137 156 t.set_app_and_language(appname, language) 138 157 except IOError: t = None … … 147 166 148 167 try: 149 t = gettext_module.translation('django', apppath, [l anguage, settings.LANGUAGE_CODE], klass)168 t = gettext_module.translation('django', apppath, [locale, default_locale], klass) 150 169 t.set_app_and_language(appname, language) 151 170 except IOError: t = None … … 180 199 if t is not None: 181 200 try: 182 return t .language()201 return to_language(t.language()) 183 202 except AttributeError: 184 203 pass … … 248 267 lang_code = request.GET.get('django_language', None) or request.POST.get('django_language', None) 249 268 if lang_code is not None: 250 if lang_code == 'en' or lang_code.startswith('en _'):269 if lang_code == 'en' or lang_code.startswith('en-'): 251 270 return lang_code 252 lang = gettext_module.find('django', globalpath, [ lang_code])271 lang = gettext_module.find('django', globalpath, [to_locale(lang_code)]) 253 272 if lang is not None: 254 273 if hasattr(request, 'session'): … … 261 280 lang_code = request.session.get('django_language', None) 262 281 if lang_code is not None: 263 if lang_code == 'en' or lang_code.startswith('en _'):282 if lang_code == 'en' or lang_code.startswith('en-'): 264 283 return lang_code 265 lang = gettext_module.find('django', globalpath, [ lang_code])284 lang = gettext_module.find('django', globalpath, [to_locale(lang_code)]) 266 285 if lang is not None: 267 286 return lang_code … … 269 288 lang_code = request.COOKIES.get('django_language', None) 270 289 if lang_code is not None: 271 if lang_code == 'en' or lang_code.startswith('en _'):290 if lang_code == 'en' or lang_code.startswith('en-'): 272 291 return lang_code 273 lang = gettext_module.find('django', globalpath, [ lang_code])292 lang = gettext_module.find('django', globalpath, [to_locale(lang_code)]) 274 293 if lang is not None: 275 294 return lang_code … … 299 318 300 319 for lang, order in langs: 301 if lang == 'en' or lang.startswith('en _'):320 if lang == 'en' or lang.startswith('en-'): 302 321 # special casing for language en and derivates, because we don't 303 322 # have an english language file available, but just fallback … … 307 326 return lang 308 327 else: 309 langfile = gettext_module.find('django', globalpath, [ lang])328 langfile = gettext_module.find('django', globalpath, [to_locale(lang)]) 310 329 if langfile: 311 330 # reconstruct the actual language from the language … … 314 333 # did find de_DE because of language normalization 315 334 lang = langfile[len(globalpath):].split('/')[1] 316 _accepted[accept] = lang335 _accepted[accept] = to_language(lang) 317 336 return lang 318 337
