mirror of https://github.com/zulip/zulip.git
Send double columned language list in page_params.
This commit is contained in:
parent
73e5289736
commit
af9f308f0e
|
@ -1,11 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
import operator
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils import translation
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from six import text_type
|
||||
from six.moves import urllib, zip_longest, zip, range
|
||||
from typing import Any, List, Dict, Optional
|
||||
|
||||
import os
|
||||
|
@ -32,6 +34,40 @@ def get_language_list():
|
|||
|
||||
return sorted(lang_list, key=lambda i: i['name'])
|
||||
|
||||
def get_language_list_for_templates(default_language):
|
||||
# type: (text_type) -> List[Dict[str, Dict[str, str]]]
|
||||
language_list = [l for l in get_language_list()
|
||||
if 'percent_translated' not in l or
|
||||
l['percent_translated'] >= 5.]
|
||||
|
||||
formatted_list = []
|
||||
lang_len = len(language_list)
|
||||
firsts_end = (lang_len // 2) + operator.mod(lang_len, 2)
|
||||
firsts = list(range(0, firsts_end))
|
||||
seconds = list(range(firsts_end, lang_len))
|
||||
assert len(firsts) + len(seconds) == lang_len
|
||||
for row in zip_longest(firsts, seconds):
|
||||
item = {}
|
||||
for position, ind in zip(['first', 'second'], row):
|
||||
if ind is None:
|
||||
continue
|
||||
|
||||
lang = language_list[ind]
|
||||
percent = name = lang['name']
|
||||
if 'percent_translated' in lang:
|
||||
percent = u"{} ({}%)".format(name, lang['percent_translated'])
|
||||
|
||||
item[position] = {
|
||||
'name': name,
|
||||
'code': lang['code'],
|
||||
'percent': percent,
|
||||
'selected': True if default_language == lang['code'] else False
|
||||
}
|
||||
|
||||
formatted_list.append(item)
|
||||
|
||||
return formatted_list
|
||||
|
||||
def get_language_name(code):
|
||||
# type: (str) -> Optional[text_type]
|
||||
for lang in get_language_list():
|
||||
|
|
|
@ -1834,6 +1834,7 @@ class HomeTest(AuthedTestCase):
|
|||
"is_admin",
|
||||
"is_zephyr_mirror_realm",
|
||||
"language_list",
|
||||
"language_list_dbl_col",
|
||||
"last_event_id",
|
||||
"left_side_userlist",
|
||||
"login_page",
|
||||
|
|
|
@ -47,7 +47,8 @@ from zerver.decorator import require_post, authenticated_json_post_view, \
|
|||
JsonableError, get_user_profile_by_email, REQ, \
|
||||
zulip_login_required
|
||||
from zerver.lib.avatar import avatar_url
|
||||
from zerver.lib.i18n import get_language_list, get_language_name
|
||||
from zerver.lib.i18n import get_language_list, get_language_name, \
|
||||
get_language_list_for_templates
|
||||
from zerver.lib.response import json_success, json_error
|
||||
from zerver.lib.str_utils import force_str
|
||||
from zerver.lib.utils import statsd, generate_random_token
|
||||
|
@ -64,7 +65,7 @@ import ujson
|
|||
import simplejson
|
||||
import re
|
||||
from six import text_type
|
||||
from six.moves import urllib
|
||||
from six.moves import urllib, zip_longest, zip, range
|
||||
import base64
|
||||
import time
|
||||
import logging
|
||||
|
@ -946,8 +947,9 @@ def home(request):
|
|||
enter_sends = user_profile.enter_sends,
|
||||
left_side_userlist = register_ret['left_side_userlist'],
|
||||
default_language = register_ret['default_language'],
|
||||
language_list = get_language_list(),
|
||||
default_language_name = get_language_name(register_ret['default_language']),
|
||||
language_list_dbl_col = get_language_list_for_templates(register_ret['default_language']),
|
||||
language_list = get_language_list(),
|
||||
referrals = register_ret['referrals'],
|
||||
realm_emoji = register_ret['realm_emoji'],
|
||||
needs_tutorial = needs_tutorial,
|
||||
|
|
Loading…
Reference in New Issue