<s> import datetime <EOL> from django . utils . translation import LANGUAGE_SESSION_KEY , get_language <EOL> from django . conf import settings <EOL> class LanguageCookieMiddleware ( object ) : <EOL> def process_response ( self , request , response ) : <EOL> language = get_language ( ) <EOL> if hasattr ( request , '<STR_LIT>' ) : <EOL> session_language = request . session . get ( LANGUAGE_SESSION_KEY , None ) <EOL> if session_language and not session_language == language : <EOL> request . session [ LANGUAGE_SESSION_KEY ] = language <EOL> request . session . save ( ) <EOL> if settings . LANGUAGE_COOKIE_NAME in request . COOKIES and request . COOKIES [ settings . LANGUAGE_COOKIE_NAME ] == language : <EOL> return response <EOL> max_age = <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> <EOL> expires = datetime . datetime . utcnow ( ) + datetime . timedelta ( seconds = max_age ) <EOL> response . set_cookie ( settings . LANGUAGE_COOKIE_NAME , language , expires = expires ) <EOL> return response </s>
