def _get_locale(self): """The locale of the incoming request. If a locale is unsupported, the default english locale is used. If the locale is assigned it will be stored in the session so that that language changes are persistent. """ if self._locale is not None: return self._locale rv = self.session.get('locale') if rv is not None: rv = Locale.parse(rv) # we could trust the cookie here because it's signed, but we do not # because the configuration could have changed in the meantime. if not has_section(rv): rv = None if rv is None: rv = select_locale(self.accept_languages) self._locale = rv return rv
def _set_locale(self, locale): self._locale = Locale.parse(locale) self.__dict__.pop('translations', None) self.session['locale'] = str(self._locale)