Changeset 1204
- Timestamp:
- 11/12/05 15:27:46 (3 years ago)
- Files:
-
- django/trunk/django/utils/translation.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/utils/translation.py
r1095 r1204 257 257 """ 258 258 Checks whether there is a global language file for the given language code. 259 This is used to decide whether a user-provided language is available. 259 This is used to decide whether a user-provided language is available. this is 260 only used for language codes from either the cookies or session. 260 261 """ 261 262 from django.conf import settings … … 269 270 """ 270 271 Analyzes the request to find what language the user wants the system to show. 272 Only languages listed in settings.LANGUAGES are taken into account. If the user 273 requests a sublanguage where we have a main language, we send out the main language. 271 274 """ 272 275 global _accepted 273 276 from django.conf import settings 274 277 globalpath = os.path.join(os.path.dirname(settings.__file__), 'locale') 278 supported = dict(settings.LANGUAGES) 275 279 276 280 if hasattr(request, 'session'): 277 281 lang_code = request.session.get('django_language', None) 278 if lang_code i s not None and check_for_language(lang_code):282 if lang_code in supported and lang_code is not None and check_for_language(lang_code): 279 283 return lang_code 280 284 281 285 lang_code = request.COOKIES.get('django_language', None) 282 if lang_code i s not None and check_for_language(lang_code):286 if lang_code in supported and lang_code is not None and check_for_language(lang_code): 283 287 return lang_code 284 288 … … 298 302 lang = el 299 303 order = 100 300 if lang.find('-') >= 0: 301 (lang, sublang) = lang.split('-') 302 lang = lang.lower() + '_' + sublang.upper() 303 return (lang, order) 304 p = lang.find('-') 305 if p >= 0: 306 mainlang = lang[:p] 307 else: 308 mainlang = lang 309 return (lang, mainlang, order) 304 310 305 311 langs = [_parsed(el) for el in accept.split(',')] 306 langs.sort(lambda a,b: -1*cmp(a[1], b[1])) 307 308 for lang, order in langs: 309 langfile = gettext_module.find('django', globalpath, [to_locale(lang)]) 310 if langfile: 311 # reconstruct the actual language from the language 312 # filename, because otherwise we might incorrectly 313 # report de_DE if we only have de available, but 314 # did find de_DE because of language normalization 315 lang = langfile[len(globalpath):].split(os.path.sep)[1] 316 _accepted[accept] = lang 317 return lang 312 langs.sort(lambda a,b: -1*cmp(a[2], b[2])) 313 314 for lang, mainlang, order in langs: 315 if lang in supported or mainlang in supported: 316 langfile = gettext_module.find('django', globalpath, [to_locale(lang)]) 317 if langfile: 318 # reconstruct the actual language from the language 319 # filename, because otherwise we might incorrectly 320 # report de_DE if we only have de available, but 321 # did find de_DE because of language normalization 322 lang = langfile[len(globalpath):].split(os.path.sep)[1] 323 _accepted[accept] = lang 324 return lang 318 325 319 326 return settings.LANGUAGE_CODE
