From bc57b82753645d33da67fff94636a7314af1da19 Mon Sep 17 00:00:00 2001 From: str4d Date: Wed, 19 Dec 2012 12:13:51 +0000 Subject: [PATCH] Added shorthand functions to make language handling more stable --- i2p2www/__init__.py | 18 ++++++++++++++++++ i2p2www/pages/global/nav.html | 15 ++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/i2p2www/__init__.py b/i2p2www/__init__.py index beccae24..ba4d228b 100644 --- a/i2p2www/__init__.py +++ b/i2p2www/__init__.py @@ -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) diff --git a/i2p2www/pages/global/nav.html b/i2p2www/pages/global/nav.html index 31b58380..eea2bed0 100644 --- a/i2p2www/pages/global/nav.html +++ b/i2p2www/pages/global/nav.html @@ -2,11 +2,11 @@
  • {{ _('Team') }}
  • +
  • {{ _('Blog') }}
  • {{ _('Hall of Fame') }}
  • {{ _('Papers and presentations') }}
  • {{ _('Contact us') }}
  • @@ -125,12 +126,12 @@
  • {{ _('Bounties') }}
  • -
  • {{ _('Meetings') }}
  • +
  • {{ _('Meetings') }}
  • {{ _('Roadmap') }}
  • {{ _('Task list') }}
  • -
  • {{ _('Language') }} +
  • {{ _('Language') }} {% include "global/lang.html" %}