forked from I2P_Developers/i2p.www
Added shorthand functions to make language handling more stable
This commit is contained in:
@@ -192,6 +192,22 @@ def utility_processor():
|
||||
else:
|
||||
return url_for('site_show', lang=lang)
|
||||
|
||||
# Shorthand for getting a language-specific url
|
||||
def get_url_with_lang(endpoint, **args):
|
||||
lang = 'en'
|
||||
if hasattr(g, 'lang') and g.lang:
|
||||
lang = g.lang
|
||||
return url_for(endpoint, lang=lang, **args)
|
||||
|
||||
# Get a specific language flag, or the flag for the current language
|
||||
def get_flag(lang=None):
|
||||
if not lang:
|
||||
if hasattr(g, 'lang') and g.lang:
|
||||
lang = g.lang
|
||||
else:
|
||||
lang = 'en'
|
||||
return url_for('static', filename='images/flags/'+lang+'.png')
|
||||
|
||||
# Provide the canonical link to the current page
|
||||
def get_canonical_link():
|
||||
protocol = request.url.split('//')[0]
|
||||
@@ -235,6 +251,8 @@ def utility_processor():
|
||||
url_for_other_page=url_for_other_page,
|
||||
change_theme=change_theme,
|
||||
site_url=get_site_url,
|
||||
get_url=get_url_with_lang,
|
||||
get_flag=get_flag,
|
||||
canonical=get_canonical_link)
|
||||
|
||||
|
||||
|
@@ -2,11 +2,11 @@
|
||||
<ul>
|
||||
<li class="has-sub"><a href="#"><span>{{ _('Download') }}</span></a>
|
||||
<ul>
|
||||
<li><a href="{{ url_for('downloads_list', lang=g.lang) }}"><span>{{ _('Download I2P') }}</span></a></li>
|
||||
<li><a href="{{ url_for('downloads_select', file=ver('i2pinstall_%s_windows.exe')) }}"><span>{{ _('Windows installer') }}</span></a></li>
|
||||
<li><a href="{{ url_for('downloads_select', file=ver('i2pinstall_%s.jar')) }}"><span>{{ _('Linux / OS X / BSD / Solaris installer') }}</span></a></li>
|
||||
<li><a href="{{ url_for('downloads_select', file='debian') }}"><span>{{ _('Debian / Ubuntu packages') }}</span></a></li>
|
||||
<li><a href="{{ url_for('downloads_select', file=ver('i2psource_%s.tar.bz2')) }}"><span>{{ _('Source package') }}</span></a></li>
|
||||
<li><a href="{{ get_url('downloads_list') }}"><span>{{ _('Download I2P') }}</span></a></li>
|
||||
<li><a href="{{ get_url('downloads_select', file=ver('i2pinstall_%s_windows.exe')) }}"><span>{{ _('Windows installer') }}</span></a></li>
|
||||
<li><a href="{{ get_url('downloads_select', file=ver('i2pinstall_%s.jar')) }}"><span>{{ _('Linux / OS X / BSD / Solaris installer') }}</span></a></li>
|
||||
<li><a href="{{ get_url('downloads_select', file='debian') }}"><span>{{ _('Debian / Ubuntu packages') }}</span></a></li>
|
||||
<li><a href="{{ get_url('downloads_select', file=ver('i2psource_%s.tar.bz2')) }}"><span>{{ _('Source package') }}</span></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-sub"><a href="#"><span>{{ _('About') }}</span></a>
|
||||
@@ -90,6 +90,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="{{ site_url('about/team') }}"><span>{{ _('Team') }}</span></a></li>
|
||||
<li><a href="{{ get_url('blog_index') }}"><span>{{ _('Blog') }}</span></a></li>
|
||||
<li><a href="{{ site_url('about/halloffame') }}"><span>{{ _('Hall of Fame') }}</span></a></li>
|
||||
<li><a href="{{ site_url('about/papers') }}"><span>{{ _('Papers and presentations') }}</span></a></li>
|
||||
<li><a href="{{ site_url('about/contact') }}"><span>{{ _('Contact us') }}</span></a></li>
|
||||
@@ -125,12 +126,12 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="{{ site_url('volunteer/bounties') }}"><span>{{ _('Bounties') }}</span></a></li>
|
||||
<li><a href="{{ url_for('meetings_index', lang=g.lang) }}"><span>{{ _('Meetings') }}</span></a></li>
|
||||
<li><a href="{{ get_url('meetings_index') }}"><span>{{ _('Meetings') }}</span></a></li>
|
||||
<li><a href="{{ site_url('volunteer/roadmap') }}"><span>{{ _('Roadmap') }}</span></a></li>
|
||||
<li><a href="{{ site_url('volunteer/todo') }}"><span>{{ _('Task list') }}</span></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="has-sub right"><a href="#"><span><img src="{{ url_for('static', filename='images/flags/'+g.lang+'.png') }}" /> {{ _('Language') }}</span></a>
|
||||
<li class="has-sub right"><a href="#"><span><img src="{{ get_flag() }}" /> {{ _('Language') }}</span></a>
|
||||
{% include "global/lang.html" %}
|
||||
</li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user