def set_lang(): user = get_user() if not user: return redirect(url_for('front')) new_lang = request.form['lang'] if new_lang != user.lang and new_lang in ch.get_supported_languages(): user.lang = new_lang user.save() return redirect(url_for('settings'))
def _set_lang(self, lang): supported = ch.get_supported_languages() if lang in supported: user = self._get_tg().user user.lang = lang user.save() self.lang = load_language(user) self.sender.sendMessage(self.t('lang_set')) else: self.sender.sendMessage(self.t('no_such_lang').format(u', '.join(sorted(supported))))
def load_user_language(): g.supported_languages = ch.get_supported_languages() user = get_user() if user: lang = user.lang else: lang = get_language_from_request() data = ch.load_language('', lang) tasks = ch.load_language('tasks', lang) data['tasks'] = tasks g.lang = data
def settings(): user = get_user() if not user: return redirect(url_for('login', next=request.path)) if user: code = user.generate_code() else: code = '' return render_template('connect.html', user=user, code=code, langs=ch.get_supported_languages(), lang=g.lang)
def get_language_from_request(): supported = ch.get_supported_languages() accepted = request.headers.get('Accept-Language', '') lang = 'en' for lpart in accepted.split(','): if ';' in lpart: lpart = lpart[:lpart.index(';')] pieces = lpart.strip().split('-') if len(pieces) >= 2: testlang = '{}_{}'.format(pieces[0].lower(), pieces[1].upper()) if testlang in supported: lang = testlang break if len(pieces) == 1 and pieces[0].lower() in supported: lang = pieces[0].lower() break return lang