Ejemplo n.º 1
0
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'))
Ejemplo n.º 2
0
 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))))
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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