Skip to content

Commit

Permalink
Fail more gracefully if locales are not built
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Jun 12, 2019
1 parent 57e9df5 commit 6872464
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion indico/modules/users/forms.py
Expand Up @@ -67,7 +67,7 @@ class UserPreferencesForm(IndicoForm):
def __init__(self, *args, **kwargs):
super(UserPreferencesForm, self).__init__(*args, **kwargs)

locales = [(code, '{} ({})'.format(name, territory))
locales = [(code, '{} ({})'.format(name, territory) if territory else name)
for code, (name, territory) in get_all_locales().iteritems()]
self.lang.choices = sorted(locales, key=itemgetter(1))
self.timezone.choices = zip(common_timezones, common_timezones)
Expand Down
6 changes: 3 additions & 3 deletions indico/web/client/js/react/components/UserMenu.jsx
Expand Up @@ -87,7 +87,7 @@ export default function UserMenu({userData, languages, hasLoadedConfig, hasLoade
}}
options={Object.entries(languages).map(([key, [name, territory]]) => ({
key,
text: `${name} (${territory})`,
text: territory ? `${name} (${territory})` : name,
value: key,
}))}
/>
Expand All @@ -102,7 +102,7 @@ export default function UserMenu({userData, languages, hasLoadedConfig, hasLoade
</div>
);

const langInfo = languages[language];
const langInfo = languages[language] || [language, null];
return (
<Dropdown trigger={avatar} pointing="top right">
<Dropdown.Menu>
Expand All @@ -117,7 +117,7 @@ export default function UserMenu({userData, languages, hasLoadedConfig, hasLoade
<Dropdown.Header>
{languageSelector(
<>
<Icon name="globe" /> {`${langInfo[0]} (${langInfo[1]})`}
<Icon name="globe" /> {langInfo[1] ? `${langInfo[0]} (${langInfo[1]})` : langInfo[0]}
</>
)}
</Dropdown.Header>
Expand Down
11 changes: 7 additions & 4 deletions indico/web/templates/_session_bar.html
Expand Up @@ -163,29 +163,32 @@


{% macro _render_language_selector(languages, lightweight=false) %}
{% set lang = languages[session.lang][0] if session.lang in languages else _('English') %}
{% if lightweight %}
<a id="language-selector-link" class="arrow js-dropdown" data-toggle="dropdown">
{% trans lang=languages[session.lang][0] %}My language ({{ lang }}){% endtrans %}
{% trans %}My language ({{ lang }}){% endtrans %}
</a>
{% else %}
<a id="language-selector-link" class="arrow icon-earth i-button js-dropdown" data-toggle="dropdown">
{{ languages[session.lang][0] }}
{{ lang }}
</a>
{% endif %}
<ul class="dropdown">
{% for name, (title, territory) in languages|dictsort(by='value') %}
<li>
{% if name == session.lang %}
<a class="disabled" title="{% trans %}This is your current language.{% endtrans %}">
{{- title }} ({{ territory }})
{{- title -}}
{%- if territory %} ({{ territory }}){% endif -%}
</a>
{% else %}
<a data-href="{{ url_for('core.change_lang') }}"
data-method="POST"
data-params='{{ {'lang': name}|tojson|forceescape }}'
data-reload-after
data-ajax>
{{ title }} ({{ territory }})
{{- title -}}
{%- if territory %} ({{ territory }}){% endif -%}
</a>
{% endif %}
</li>
Expand Down

0 comments on commit 6872464

Please sign in to comment.