<s> from __future__ import unicode_literals <EOL> from django . utils import translation <EOL> from django . db . models import ObjectDoesNotExist <EOL> from pybb import util <EOL> class PybbMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> if request . user . is_authenticated ( ) : <EOL> try : <EOL> profile = util . get_pybb_profile ( request . user ) <EOL> except ObjectDoesNotExist : <EOL> from pybb . signals import user_saved <EOL> user_saved ( request . user , created = True ) <EOL> profile = util . get_pybb_profile ( request . user ) <EOL> if not profile . language : <EOL> profile . language = translation . get_language_from_request ( request ) <EOL> profile . save ( ) <EOL> request . session [ '<STR_LIT>' ] = profile . language <EOL> translation . activate ( profile . language ) <EOL> request . LANGUAGE_CODE = translation . get_language ( ) </s>
